0

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.**

  • I'm sorry, but there is so much wrong doing here that I think that this question isn't solvable. In order to guide you somehow anyway, [threaded progressbar](https://stackoverflow.com/a/63837385/13629335), also see [when to use lambda in command](https://stackoverflow.com/a/61156251/13629335) and you may want to look at [pill to kill a thread](https://stackoverflow.com/a/36499538/13629335). I'm voting to close this question while it asks for more than one issue. – Thingamabobs Jun 06 '22 at 06:06
  • @Thingamabobs please just forget about progress bar and button lambda. I need to know why when i press cancel the ui gets frozen and becomes unresponsive – rfgassdfv fgSA Jun 06 '22 at 06:17
  • `self.beep_th.join()` will block the mainloop of tkinter till the thread joins at the end of its lifetime to this point. There are different publicly available approaches to use threads with tkinter. You are using none of them and your a own approach has several issues. You should do a research for threading and tkinter you will find some guidance and approaches that will help you out. – Thingamabobs Jun 06 '22 at 06:25
  • In addition it seems not wise to me to make your program able to stop your thread while working with files and have not done any clean up. – Thingamabobs Jun 06 '22 at 06:27

0 Answers0