我想制作一个“程序”,当您按下按钮并打印出一个变量时更新标签,但是使用我的代码它不起作用。有人可以帮帮我吗?
提前致谢!
from Tkinter import *
root = Tk()
x = 0
def test():
global x
x += 1
label_1.update()
label_1 = Label(root, text=x)
button_1 = Button(root, text='Click', command=test)
button_1.grid(row=0, column=0)
label_1.grid(row=0, column=1)
root.mainloop()
最佳答案
而不是 label_1.update()
(doesn't do anything close to what you think it does),reconfigure the widget使用 label_1.config(text=x)
。
关于python - 按下按钮时更新 Tkinter 中的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30763769/