Reputation: 31
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
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