简体   繁体   中英

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.

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. That is why there are overlapped text.

You need to create the label once outside the function:

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=...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM