0

So for my project when I click a button - the page must navigate to another. And when I do this each time it creates a different window (hence resulting in a lot of windows) or keeps stacking on top of each other

Currently I have a admin/student choice page. And if I click on the student page it will run the student log in function and this applies the same for the admin.

I want to keep the background of the windows consistent as well - but I am unable to do so and on top of that I have no clue on how to navigate via the pages - I have looked at a few videos but I did not really understand it.

contains 2 buttons admin and student which should navigate to different "windows" when clicked

def mainPage():
""""Starting Page - which navigates to the approporate login, when user logs it navigates back to this window"""
    root = Tk()
    root.geometry('1024x600')
    load = PIL.Image.open('Image//book.jpg')
    render = ImageTk.PhotoImage(load)
    img =Label(root, image = render)
    img.place(x=0, y=0)
    my_font = font.Font(size = 15)
    buttonFrame = Frame(root, width = 600, height=300, bg="grey")
    buttonFrame.grid(row = 0, column = 0, padx= 10, pady=2, sticky="")

    label = Label(buttonFrame, text = "Pick a Log-in", bg = "white", font=my_font).grid(row = 1, column=1, sticky="", padx=10, pady=10)
    button = Button(buttonFrame, text = "Admin",command = adminLogin, width=30, height = 5, font=my_font).grid(row=2, column=1, sticky = "", padx= 10, pady=10)
    button2 = Button(buttonFrame, text = "Student", command = studentLogin, width = 30, height=5, font=my_font).grid(row = 3, column=1, sticky="", padx = 10, pady=10)


    root.mainloop()
def studentLogin():
    root = Tk()
    
    root.geometry('1024x600')
    load = PIL.Image.open('Image//book.jpg')
    render = ImageTk.PhotoImage(load)
    img =Label(root, image = render)
    img.place(x=0, y=0)

    my_font = font.Font(size = 15)
    buttonFrame = Frame(root, width = 600, height=600, bg="grey")
    buttonFrame.grid(row = 0, column = 0, padx= 10, pady=2, sticky="")
    root.grid_rowconfigure(0, weight=1)
    root.grid_columnconfigure(0, weight=1)
    label = Label (buttonFrame, text="Welcome", font=('Helvetica', 18, 'bold'), bg="white").grid(row = 1, column = 1,sticky="", padx=10, pady=10)
    label = Label(buttonFrame, text="Username", font = my_font).grid(row=2, column=1, padx=10, pady=10)
    usernameEntry = Entry(buttonFrame).grid(row=2, column=2, padx=10, pady=10)
    
   
    root.mainloop()
AKR
  • 21
  • 4
  • If you want the simple answer: if you use `grid` then use `grid_forget` on the page you want to remove and call `grid` on the page you want to show. If you use `pack` or `place` it's the same thing except call `pack_forget` or `place_forget`, respectively. – OneMadGypsy Aug 21 '20 at 17:03
  • Please fix the indentation of your code. – Bryan Oakley Aug 21 '20 at 17:40

1 Answers1

-1

Maybe try with PySimpleGUI :)

It has a convenient window.Hide() or window.UnHide() for these cases. Its also a great library for developping GUIs, good documentation, great support, and easy to pick up.

For tkinter, you could try with

root.withdraw() 

and

root.update()
root.deiconify()
Bastien Harkins
  • 295
  • 1
  • 7
  • Oh okay thank you! with the tkinter option - where would you put in the lines - I have updated the post :D – AKR Aug 21 '20 at 16:51
  • This doesn't even begin to answer the question. `root.withdraw()` and `root.deiconify` affect whole windows. The OP wants to switch pages within a single window. – Bryan Oakley Aug 21 '20 at 17:41