Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Tkinter – Unable to figure out how to update windows

First off, I’m new to coding. And I’m following a course on it. But in the meantime I want to test myself and figure things out for myself and "learn on the job" a bit with more hands on coding that I can use right away.

I’ve written below code to try and figure out to make a main window with 2 buttons. If I press a button, it should change the screen into the second/third screen. But instead if I fire up my exe.
It opens all 3 windows right away in separate windows. And once I press a button it opens another window. But what I would want is that the main window get’s "updated" to show only the labels/pictures/buttons etc (which I did not include in the .py yet).


from tkinter import *

def second_window1():
    second_window1 = Toplevel(main)
    second_window1.title("Second window")
    second_window1.geometry("414x896")
    Label(second_window1, text ="This is the second window")#.pack()

def third_window1():
    third_window1 = Toplevel(main)
    third_window1.title("Third window")
    third_window1.geometry("414x896")
    Label(third_window1, text ="This is the third window")#.pack()  

main = Tk()
main.title("Main Screen")
main.geometry('414x896')
main.configure(background = "azure2")
main.resizable(False, False)

Label(main, text = "Label_1", fg = "chartreuse2", bg = "ghostwhite", font = "Helvetica 16 bold").grid(row=1, column=1)

second_window = Tk()
second_window.title("Second Screen")
second_window.geometry('414x896')
second_window.configure(background = "azure2")
second_window.resizable(False, False)

Label(main, text = "Label_2", fg = "chartreuse2", bg = "ghostwhite", font = "Helvetica 16 bold").grid(row=1, column=1)

third_window = Tk()
third_window.title("Third Screen")
third_window.geometry('414x896')
third_window.configure(background = "azure2")
third_window.resizable(False, False)

Label(main, text = "Label_3", fg = "chartreuse2", bg = "ghostwhite", font = "Helvetica 16 bold").grid(row=1, column=1)

btn = Button(main, text ="Second Screen", command = second_window1).grid(row=1, column=1)
btn = Button(main, text ="Third Screen", command = third_window1).grid(row=2, column=1)

mainloop()

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel


>Solution :

You would want to use a ttk.Notebook for that.
See e.g. at TkDocs.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading