1

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?

1 Answer 1

1

You never call frame3.grid(...), so frame3 is never made visible.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh my, I'm blind! I always forget to declare grid or pack :D thank you for the answer, now it works perfectly. By the way, I don't know if here is a convention or not.. anyways, I'm adding [SOLVED] to the title, so other people know that the problem was, indeed, solved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.