Reputation: 41
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:
Upvotes: 4
Views: 1079
Reputation: 4595
Short way to do this. W/out using ==1
and ==2
.
snippet:
description_label = Label(frame1)
description_label.grid(row=4, column=0, columnspan=4)
def select_description(event):
choice = list_profiles.get(ANCHOR)
if choice:
description_label.config(text=...)
else:
description_label.config(text=...)
Upvotes: 0
Reputation: 47183
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=...)
Upvotes: 3