tkinter按钮直到整个功能(与按钮关联)被处理后才显示标签

2024-04-26 05:31:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用python 2.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分钟后显示,即在计算后显示。我需要的文本(标签)显示后不久,按钮被点击。你知道吗

谢谢你的帮助。你知道吗


Tags: textself功能place标签width按钮tk
1条回答
网友
1楼 · 发布于 2024-04-26 05:31:47

在开始长时间计算之前调用update

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

但你最好用线

相关问题 更多 >