I'm currently working on a project using the Tkinter module in Python. I am using the menu widget and for each command on the menu there is another command associated with it. Each of these commands opens a new frame. I am using the grid geometry manager.
My problem is that I would like the user to be able to switch from frame to frame but when I try doing this, the frames overlap each other instead of switching. How can I get the active frame to hide and then open up a new frame? I don't want to have to iterate through a list of possible frames and tell them all to hide.
Here is the code I've written so far:
import Tkinter as tkinter
root = tkinter.Tk()
root.minsize(400,300)
welcome = tkinter.Frame(root).grid()
label = tkinter.Label(welcome, text="Welcome to my program").grid(row=0, column=3)
button = tkinter.Button(welcome,text="Exit",command=root.destroy).grid(row=3, column=1)
def newFrame():
newFrame = tkinter.Frame(root).grid()
newFrame_name = tkinter.Label(newFrame, text="This is another frame").grid()
menu = tkinter.Menu(root)
root.config(menu=menu)
main_menu = tkinter.Menu(menu)
menu.add_cascade(label="Main Menu", menu= main_menu)
main_menu.add_command(label="New Frame", command=newFrame)
#menu.add_command(label="Exit", command=root.destroy, menu= filemenu)
root.mainloop()
When the user selects the New Frame option from the menu, I want the newFrame to replace the welcome frame.