Python tkinter-按钮不可用';t在处理完整个功能(与按钮相关)之前,不要显示标签

Python tkinter-按钮不可用';t在处理完整个功能(与按钮相关)之前,不要显示标签,python,tkinter,Python,Tkinter,我正在使用python2.7中的tkinter创建gui。在GUI中有执行功能的按钮。问题是,当点击按钮时,直到整个功能完成,它才会显示标签。示例代码: button4=tk.Button(self,text="MEMORY",height=1,width=20,font=LABEL_FONT,fg=mycolor,bg='light blue',command=lambda: controller.show_frame(memory)) button4.place(relx=0.6, rel

我正在使用
python2.7
中的
tkinter
创建gui。在GUI中有执行功能的按钮。问题是,当点击按钮时,直到整个功能完成,它才会显示标签。示例代码:

button4=tk.Button(self,text="MEMORY",height=1,width=20,font=LABEL_FONT,fg=mycolor,bg='light blue',command=lambda: controller.show_frame(memory)) 
button4.place(relx=0.6, rely=.53,width=120, anchor="sw")
与按钮关联的功能是:

def memory(self):
    label = tk.Label(
        self,
        text="Calculating, Please wait...",
        font=text_font,
        fg="white",
        bg=mycolor)
    label.place(relx=.0005, rely=.17)
    f3 = open('filename' ,"r")
    list1= list()
    list2= list()

    # Calculating some values which takes around 5 minutes as the lists are huge
此处文本“请稍候…”仅在5分钟后显示,即在计算之后。我需要文本(标签)显示后不久,按钮被点击


感谢您的帮助。

在开始长时间计算之前,请致电更新

def memory(self):
    label = tk.Label(
        self,
        text="Calculating, Please wait...",
        font=text_font,
        fg="white",
        bg=mycolor)
    label.place(relx=.0005, rely=.17)
    self.update()
    f3 = open('filename' ,"r")
    list1= list()
    list2= list()

    # Calculating some values which takes around 5 minutes as the lists are huge

但在开始长时间计算之前,最好使用线程调用更新

def memory(self):
    label = tk.Label(
        self,
        text="Calculating, Please wait...",
        font=text_font,
        fg="white",
        bg=mycolor)
    label.place(relx=.0005, rely=.17)
    self.update()
    f3 = open('filename' ,"r")
    list1= list()
    list2= list()

    # Calculating some values which takes around 5 minutes as the lists are huge

但您最好使用thread

Create函数来更改标签,并在计算前执行call text函数时执行需要执行的操作:)Create函数来更改标签,并在计算前执行call text函数时执行需要执行的操作:)