I am simply trying to make a Radiobutton
GUI using tkinter
. In which I want to change/replace the "Select your toppings" Label
(myLabel
) every time the user selects any Radiobutton
with that Radiobutton
name. So, the error which I am facing is instead of replacing that label a new label is created just below even though I am using a global Label
.
from tkinter import *
root = Tk()
Toppings = [
["Pepperoni", "Pepperoni"],
["Cheese", "Cheese"],
["Mushroom", "Mushroom"],
["Onion", "Onion"]
]
pizza = StringVar()
pizza.set("Select your toppings")
for topping, value in Toppings:
Radiobutton(root, text = topping, variable = pizza, value = value). pack(anchor = W)
myLabel = Label(root, text = pizza.get())
myLabel.pack()
def clicked(value):
global myLabel
myLabel.grid_forget()
myLabel = Label(root, text = value)
myLabel.pack()
myButton = Button(root, text="CLick me!", command = lambda: clicked(pizza.get()))
myButton.pack()
root.mainloop()