Python 为什么在Tkinter窗口中创建标签之前执行time函数和print()
输出: 5秒后 打印:创建标签 然后标签出现 ** 如何使标签首先显示在窗口上,然后打印()标签创建消息 请帮我做这个。。 **只需在(ms,func,*args)之后使用Python 为什么在Tkinter窗口中创建标签之前执行time函数和print(),python,user-interface,tkinter,Python,User Interface,Tkinter,输出: 5秒后 打印:创建标签 然后标签出现 ** 如何使标签首先显示在窗口上,然后打印()标签创建消息 请帮我做这个。。 **只需在(ms,func,*args)之后使用。这是你的一个例子 def createLabel(): l = label(text='Label Created') l.grid(row=10, column=3) time.sleep(5) print('Label Created') b = Button(text='Click t
。这是你的一个例子
def createLabel():
l = label(text='Label Created')
l.grid(row=10, column=3)
time.sleep(5)
print('Label Created')
b = Button(text='Click to create a label', command=createLabel)
他们以前不执行死刑。简单地说,用户界面直到
createLabel
返回并且您明确地告诉程序睡眠5秒后才会更新。这个网站上有无数关于更新小部件的问题,你做过研究吗?如果您可以分享您搜索的内容,我们可以编辑一些问题或答案,以便更容易发现。您实际上不需要创建prnt
函数,回调函数的参数可以直接传递到after(ms,func,*args)
方法。所以它应该像b.after(5000,打印,'Label Created')
。
from tkinter import *
import tkinter as tk
def createLabel():
l = Label(text='Label Created')
l.pack(side=BOTTOM)
b.after(5000, print, 'Label created')
root = tk.Tk()
b = Button(root,text='Click to create a label', command=createLabel)
b.pack(side=TOP)
root.mainloop()