how do you deal with the function that takes a long time in Tkinter?

Category: python tkinter time (0 Views)

I'm working with Tkinter, I have a function that takes a long time to process (10 minutes) so I want to display a frame before the end of the process and then display whatever the function display so I was doing that

class App(customtkinter.CTk):

    WIDTH = 950
    HEIGHT = 520

    def __init__(self):
        super().__init__()

        self.button_3 = customtkinter.CTkButton(
            master=self.frame_left,
            text=" Translation",
            width=160,
            command=lambda: [self.waiting_func(imported_file)])
        self.button_3.grid(row=4, column=0, pady=10, padx=20)

    def waiting_func(self, imported_file):
        fr = Frame(self.frame_right, bg="red")
        fr.grid(row=1,
                column=0,
                rowspan=9,
                columnspan=2,
                pady=20,
                padx=10,
                sticky="nswe")
        Translaion_main(self, imported_file) #this is the functin with the long process

but the frame fr doesn't show before the end of the process (after the 10 min)

I tried the progress bar didn't work as well

can someone help?

🔴 No definitive solution yet

📌 Solution 1

You can create a thread to run the task in the background: https://superfastpython.com/thread-long-running-background-task/