0
我在我的應用程序線程中添加了一些列表,然後我想在其他屏幕上打印它,但程序在打印後運行線程,它是給我的錯誤,我的列表中沒有任何東西。我需要停止該程序,直到線程完成,我該怎麼做?我試圖用。加入(),但它是沒有工作...感謝您的幫助kivy-需要等到線程完成
我的應用程序:
class LoginScreen(GridLayout):
def __init__(self, **kwargs):
super(LoginScreen, self).__init__(**kwargs)
self.cols = 2
self.add_widget(Label(text='username'))
self.username = TextInput(multiline=False)
self.add_widget(self.username)
self.add_widget(Label(text='Password'))
self.password = TextInput(multiline=False, password=True)
self.add_widget(self.password)
self.submit_button = Button(text='sumbit',size_hint=(.5,
.25),font_size=20)
self.submit_button.bind(on_press=self.submit_username)
self.add_widget(self.submit_button)
def submit_username(self, *args):
self.msg=threading.Thread(target=send_data(self.username.text))
self.msg.start()
self.msg.join()
sm.current = 'searchi'
sm.transition.direction = 'left'
def send_data(name):
my_socket = socket.socket()
my_socket.connect(('127.0.0.1', 8093))
my_socket.send(name.encode('utf-8'))
name,address = my_socket.recvfrom(1024)
msg = name.decode('utf-8')
alist.append(msg)
my_socket.close()
# Declare both screens
class Searchi(Screen):
def __init__(self, **kwargs):
super(Searchi, self).__init__(**kwargs)
self.add_widget(Label(text=alist[0]))
列表中有「味精」如果我刪除行「self.add_widget (Label(text = alist [0]))「,那麼在recv行中沒有問題。我只需要等到線程完成。
我發佈的答案有幫助嗎? – Tshirtman