我使用 python 在线程中创建了一个根窗口。然后接下来是我需要销毁它并创建一个新窗口,但是出现一个错误,说线程只能启动一次。我怎样才能开始一个新的窗口窗体?
class SignUp(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.mw=Tkinter.Tk()
self.mw.geometry("800x600""+290+50")
self.mw.title("Registration Form")
self.mw.resizable(width=False,height=False)
self.regs=Tkinter.Button(self.canvas, text= "Log-in",font="{Arial} 12 {bold}",bg='black',fg='white',command=self.login)
self.regs.place(rely=0.82,relx=0.1,relwidth=0.30)
self.start()
def login(self):
self.mw.destroy()
self.mw.geometry("650x700""+350+20")
self.mw.title("Py cos")
self.mw.resizable(width=False,height=False)
self.canvas= Tkinter.Canvas(self.mw)
self.canvas.pack(expand='yes',fil='both')
self.photo= Tkinter.PhotoImage(file='Image/vote.gif')
self.canvas.create_image(0,0,image=self.photo,anchor='nw')
def run(self):
self.client = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
self.client.connect(('localhost',500))
#self.client.connect(('169.254.57.141',500))
self.rec=self.client.recv(1024)
self.canvas.create_text(105,595,text=self.rec, font="{Arial} 8 {bold}", fill = 'yellow')
if __name__=="__main__":
SignUp().mw.mainloop()
这段代码给了我
RuntimeError: threads can only be started once
如何在避免此错误的同时创建一个窗口、销毁它并再次创建它?