I'm trying to make a little GUI for a program. I'm using grid to put some frames in a root window. I have 3 frames: normally, frame 1 and frame 2 are located in row=0 column=0 (frame1) and row=0 column=1. Frame 3 is not shown by default. On frame1 i have two buttons: the idea is, by pressing the buttons, to switch between frame2 and frame 3,by keeping frame1 visible. Here's the code that i wrote:
from tkinter import *
def hello():
frame2.tkraise()
print('hello')
def world():
frame3.tkraise()
print('world')
root=Tk()
frame1=Frame(root)
frame2=Frame(root)
frame3=Frame(root)
frame1.grid(row=0,column=0,rowspan=2)
frame2.grid(row=0,column=1,rowspan=2)
tag1=Label(frame2,text='hello')
tag2=Label(frame3,text='world')
tag1.grid()
tag2.grid()
press1=Button(frame1,text='hello',command=hello)
press2=Button(frame1,text='world',command=world)
press1.grid(row=0)
press2.grid(row=1)
root.mainloop()
Now, if I click on "press1" or "press2" the corresponding functions are called (i can see on the terminal the respective prints "hello" and "world"), so they are working, but it doesn't change the frame. What am I missing?
You never call frame3.grid(...)
, so frame3 is never made visible.