When I press start the thread starts and cancel to stop thread. when cancel button is pressed, the ui becomes unnresponsive. File is another class that has function to convert pandas dataframes into excel.
Inpdir and outdir are input and output locations.
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.beep_th = None
self.b = None
self.stop_threads = Event()
self.controller = controller
BackGround(self)
self.lbl4 = Label(self, text='Progress', background='#080E1E', fg='White')
self.lbl4.place(x=100, y=300)
self.progress = Progressbar(self, orient=HORIZONTAL, length=500, mode='determinate')
self.progress.place(x=100, y=350)
self.btn5 = Button(self, text='Back', command=lambda: controller.show_frame("StartPage"))
self.btn5.place(x=200, y=400)
self.btn55 = Button(self, text='Start', command=lambda: [self.button_callback()])
self.btn55.place(x=250, y=400)
self.btn555 = Button(self, text='Close', command=lambda: [self.on_exit1()])
self.btn555.place(x=300, y=400)
self.btn5555 = Button(self, text='Cancel', command=lambda: [self.terminate()])
self.btn5555.place(x=350, y=400)
def button_callback(self):
self.stop_threads.clear()
self.beep_th = threading.Thread(target=self.process, daemon=True)
self.beep_th.start()
def terminate(self):
self.after(10)
self.stop_threads.set()
self.beep_th.join()
self.beep_th = None
def process(self):
while not self.stop_threads.is_set():
global file, c
file = Extract(inpdir, outdir)
c = file.read()
self.a = file.start
global b
b = file.document()
self.d = file.create()
self.stop_threads.is_set()
** I am still new to tkinter, can someone explain what to change here.**