Hello Users,
I have a python script called Master which runs continously (using while 1:). Now I want to create a simple GUI using tkinter to Start and Stop the Master script but once started, the GUI does not react and as far as I have read online, this issuse can be solved using Threading. But it seems I am not using the Threading in a correct manner as I am getting Exceptions because of this approach:
My Code Looks as follows:
Master:
I have a python script called Master which runs continously (using while 1:). Now I want to create a simple GUI using tkinter to Start and Stop the Master script but once started, the GUI does not react and as far as I have read online, this issuse can be solved using Threading. But it seems I am not using the Threading in a correct manner as I am getting Exceptions because of this approach:
Error:Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Program Files\Python27\lib\threading.py", line 801, in __bootstrap_inner
self.run()
Will be greatful to your suggestionsMy Code Looks as follows:
Master:
def Excecute(): while 1: func1() func2() # and many other functionsGUI:
import Tkinter import tkSimpleDialog import tkFileDialog import tkMessageBox import os from subprocess import Popen import sys import Master as test import threading class PST(Tkinter.Tk): def __init__(self,parent): Tkinter.Tk.__init__(self,parent) self.parent = parent self.initialize() def initialize(self): # Label self.grid() d="Sample Text" label1 = Tkinter.Label(self,text="Status :" + self.Status_Text(d),anchor="w").grid(column=0,row=0,columnspan=1,sticky='EW',padx=5,pady=5) # Button button1 = Tkinter.Button(self,text=u"Start",command=self.anfang) button1.grid(column=0,row=11,pady=10,padx=10,columnspan=1,sticky='W') button2 = Tkinter.Button(self,text=u"Beenden",command=self.beenden) button2.grid(column=0,row=11,pady=10,padx=90,sticky='W') def anfang(self): t=threading.Thread(target=test.Execute) t.start() def Status_Text(self,Meldung): Text=Meldung return (Text) def beenden(self): print("Exiting") self.destroy() sys.exit() master = CoA_PST(None) master.title('CoA PST') w = 300 h = 100 ws = master.winfo_screenwidth() hs = master.winfo_screenheight() x = (ws/2) - (w/2) y = (hs/2) - (h/2) master.geometry('%dx%d+%d+%d' % (w, h, x, y)) master.mainloop()