Gestion d'une IHM Tkinter par un thread
Bonjour,
Je voudrais gérer mon IHM par un thread (pour éviter de bloquer toute mon application avec la mainloop() ).
J'ai essayé quelque chose mais le thread ne veut pas se lancer, voici mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
import Tkinter
import threading
class GUIThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.window=GUIInterface()
def run(self):
self.window.mainloop()
def stop(self):
self.window.destroy()
class GUIInterface(Tkinter.Tk):
def __init__(self):
Tkinter.Tk.__init__(self)
self.title("Monitor")
self.labelText=Tkinter.Label(self,text="MonText")
self.labelText.pack()
self.buttonExit=Tkinter.Button(self, text="Exit",command=self.exit)
self.buttonExit.pack()
def exit(self):
self.destroy()
newGUIThread=GUIThread()
newGUIThread.start() |
Si je fais simplement newGUIThread.run() au lieu de newGUIThread.start() ma fenêtre s'affiche bien mais bien sur je n'utilise pas de thread donc mon programme reste bloqué
Python me répond:
RuntimeError: Calling Tcl from different appartment
Si vous aviez une idée...