python - 更改链接到标签的变量后如何更新 Tkinter 标签?
问题描述
例如:
from tkinter import *
root = Tk()
root.state=("zoomed")
counter = 0
word = ("Placeholder")
lbl_point = Label(root, text="Points: " + counter
lbl_point.pack
txt_guess = Entry(root, text="You're guess?")
txt_guess.pack(side=TOP)
if txt_guess.get() == word:
counter = counter + 1
print("debug" + counter)
else:
print("placeholder incorrect")
root.mainloop()
当“计数器”更改数字时,标签“lbl_point”不会更新。我试过root.update_idletasks()
在末尾添加,"if txt_guess.get() == word
但它没有改变任何东西。
任何帮助表示赞赏。
解决方案
试试这个解决方案:
lbl_point.configure(text="Points: " + counter)
推荐阅读
- c# - 如何使用 C#.Net 实现 POS 扫描仪的 DirectIO 事件?
- angular - 是否可以制作圆角的垫子进度条?
- kendo-ui - 使用显示连接值的客户端模板过滤 Kendo 网格列
- azureservicebus - 即使使用 AutoLockRenew 也会向订阅者发送重复消息
- python - 在 Python 的窗口中不将键盘输入显示为标签
- c - 归并排序的时间复杂度是恒定的
- javascript - 获取新坐标后在 mapbox 上标记新位置
- python - 通过 pandas 数据框应用生成文件哈希会为所有文件创建相同的哈希
- angular - Angular 9 的 PrimeNG Quill Editor 自定义字体大小设置问题
- flutter - Dart 获取每个特定字符的中间字符串