简体   繁体   English

在 Tkinter 中需要很长时间的 function 如何处理?

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

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我正在使用 Tkinter,我有一个 function 需要很长时间才能处理(10 分钟),所以我想在过程结束之前显示一个帧,然后显示 ZC1C425268E68385D1AB5074C 所做的任何事情

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)但帧 fr 在过程结束之前(10 分钟后)不显示

I tried the progress bar didn't work as well我试过进度条也不行

can someone help?有人可以帮忙吗?

You can create a thread to run the task in the background: https://superfastpython.com/thread-long-running-background-task/可以创建线程在后台运行任务: https://superfastpython.com/thread-long-running-background-task/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM