Fairly new to python. I am using option menus and I have labels attached to them:
from tkinter import *
root=Tk()
def f(s):
if s=="btn":
one=Label(root,text="one blah blah")
one.grid(column=1,row=2)
if s=="btn2":
two=Label(root,text="two")
two.grid(column=1,row=2)
v=StringVar(root)
v.set("f")
a=OptionMenu(root,v,"btn","btn2",command=f)
a.grid(column=1,row=1)
root.configure()
root.geometry("100x100")
root.mainloop()
I can't figure out how to make the "one blah blah" to delete the "two" so that it isn't visible when you press btn2 after pressing btn1. I have tried .grid_forget and similar stuff but I can never get it to work.
If it matters this is an example program for a larger program I am creating where there are many different option menus and labels.
You can create empty label at start and later change only text in this label
If you have to delete
Label
(because you have to put different widget - ie.Button
) then usedestroy()
BTW: you can create widgets only once and replace them - then use
grid_forget()
to hide widgetFunction can be shorter if you check all possible values for
s