Casper Josiah
Casper Josiah

Reputation: 31

How to delete and redisplay a tkinter label

I have a Dropbox and I want to print out a selected fruit option it works, But I want it to delete the previously displayed fruit and put the new selected one in it's place but instead it just displays the new one under the first

here's the program

   fruits=["apple",
        "mango",
        "pear",
        "orange"]
clicked=StringVar()
clicked.set(fruits[0])

drop=OptionMenu(root,clicked,*fruits)
drop.pack()

def Print():         
display=Label(root,text=clicked.get()).pack()

button=Button (root,text="Print",command=Print)

Upvotes: 0

Views: 63

Answers (1)

Thingamabobs
Thingamabobs

Reputation: 8037

Of course it does this, you created each time an new instance of the Label class by calling tk.Label(). The easiest solution would be to add your variable as text variable to your label.

Display = Label(root, textvariable=clicked)

https://stackoverflow.com/a/2603371

Upvotes: 1

Related Questions