[英]Label in Tkinter: change the text
I'm trying to change the value of the text of a label in tkinter, I'm using label.config()
but it seems that the previous value still appears on the screen with the new value.我正在尝试更改 tkinter 中 label 的文本值,我正在使用
label.config()
但似乎以前的值仍然以新值出现在屏幕上。
This is the code that I'm using:这是我正在使用的代码:
This is the result, the previous and the new text are together:这是结果,以前的和新的文本在一起:
Whenever select_description()
is executed, new label is created and put in same cell.每当执行
select_description()
时,都会创建新的 label 并将其放入同一单元格中。 That is why there are overlapped text.这就是为什么有重叠的文本。
You need to create the label once outside the function:您需要在 function 之外创建一次 label:
description_label = Label(frame1)
description_label.grid(row=4, column=0, columnspan=4)
def select_description(event):
choice = list_profiles.get(ANCHOR)
if choice == 1:
description_label.config(text=...)
elif choice == 2:
description_label.config(text=...)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.