python - 按下按钮时更新 Tkinter 中的标签

标签 python tkinter

我想制作一个“程序”,当您按下按钮并打印出一个变量时更新标签,但是使用我的代码它不起作用。有人可以帮帮我吗?

提前致谢!

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/

相关文章:

python - "filedescriptor out of range in select()"将 python 的子进程与 rsync 一起使用时

python - Tkinter 将行号添加到文本小部件

python - 检查tkinter窗口是否被撤回?

python - 初学者 Python 键盘 GUI 设置

python - Tkinter 中指定的 Canvas 单位是什么?

python - 在 python 的 tkinter gui 中悬停在 Canvas 上绘制的线上运行事件

python - uwsgi_param 和 proxy_set_header 的区别

python - 使用值列表迭代 df 和输出字典

python - 在 pytables CArray 中查找最大非无穷大元素

python - "TypeError: ' module ' object is not callable"在函数中初始化Gekko模块时