首页 > 解决方案 > 更改链接到标签的变量后如何更新 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 但它没有改变任何东西。

任何帮助表示赞赏。

标签: pythontkinter

解决方案


试试这个解决方案:

lbl_point.configure(text="Points: " + counter)

推荐阅读