I'm new to python and trying to make a GUI with tkinter for a study application. I'm having trouble setting up my program to be able to navigate to different pages. I used this stack overflow question to set up my code.
Using buttons in Tkinter to navigate to different pages of the application?
the problem with this particular solution is that it creates buttons at the top of the parent window that allow the user to navigate to each page in the program. It wouldn't make sense in my program to allow the user to navigate to any page at any time. How would I create a button on a specific page that allows me to navigate to a different page?
study_button()
is my attempt at this
from tkinter import *
#initializes each page as a class
class Page(Frame):
def __init__(self, *args, **kwargs):
Frame.__init__(self, *args, **kwargs)
def show(self):
self.lift()
#creates a specific page
class SelectionPage(Page):
def __init__(self, *args, **kwargs):
Page.__init__(self, *args, **kwargs)
label = Label(self, text='selection page')
label.pack()
def study_button():
studypage = StudyPage(self)
studypage.lift()
print("study")
studybutton = Button(self, text = "Study", command=study_button)
studybutton.pack()
class StudyPage(Page):
def __init__(self, *args, **kwargs):
Page.__init__(self, *args, **kwargs)
label = Label(self, text = 'this is the study page')
label.pack()
class ModifyPage(Page):
def __init__(self, *args, **kwargs):
Page.__init__(self, *args, **kwargs)
label = Label(self, text = 'this is the modify page')
label.pack()
#base page
class MainView(Frame):
def __init__(self, *args, **kwargs):
Frame.__init__(self, *args, **kwargs)
studypage = StudyPage(self)
selectionpage = SelectionPage(self)
modifypage = ModifyPage(self)
container = Frame(self)
container.pack(side="top", fill="both", expand=True)
studypage.place(in_=container, x=0, y=0, relwidth=1, relheight=1)
selectionpage.place(in_=container, x=0, y=0, relwidth=1, relheight=1)
modifypage.place(in_=container, x=0, y=0, relwidth=1, relheight=1)
selectionpage.show()
if __name__ == "__main__":
root = Tk()
main = MainView(root)
main.pack(side="top", fill="both", expand=True)
root.wm_geometry("400x400")
root.mainloop()