Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

tkinter navigate pages

import Tkinter as tk

class Page(tk.Frame):
    def __init__(self, *args, **kwargs):
        tk.Frame.__init__(self, *args, **kwargs)
    def show(self):
        self.lift()

class Page1(Page):
   def __init__(self, *args, **kwargs):
       Page.__init__(self, *args, **kwargs)
       label = tk.Label(self, text="This is page 1")
       label.pack(side="top", fill="both", expand=True)

class Page2(Page):
   def __init__(self, *args, **kwargs):
       Page.__init__(self, *args, **kwargs)
       label = tk.Label(self, text="This is page 2")
       label.pack(side="top", fill="both", expand=True)

class Page3(Page):
   def __init__(self, *args, **kwargs):
       Page.__init__(self, *args, **kwargs)
       label = tk.Label(self, text="This is page 3")
       label.pack(side="top", fill="both", expand=True)

class MainView(tk.Frame):
    def __init__(self, *args, **kwargs):
        tk.Frame.__init__(self, *args, **kwargs)
        p1 = Page1(self)
        p2 = Page2(self)
        p3 = Page3(self)

        buttonframe = tk.Frame(self)
        container = tk.Frame(self)
        buttonframe.pack(side="top", fill="x", expand=False)
        container.pack(side="top", fill="both", expand=True)

        p1.place(in_=container, x=0, y=0, relwidth=1, relheight=1)
        p2.place(in_=container, x=0, y=0, relwidth=1, relheight=1)
        p3.place(in_=container, x=0, y=0, relwidth=1, relheight=1)

        b1 = tk.Button(buttonframe, text="Page 1", command=p1.show)
        b2 = tk.Button(buttonframe, text="Page 2", command=p2.show)
        b3 = tk.Button(buttonframe, text="Page 3", command=p3.show)

        b1.pack(side="left")
        b2.pack(side="left")
        b3.pack(side="left")

        p1.show()

if __name__ == "__main__":
    root = tk.Tk()
    main = MainView(root)
    main.pack(side="top", fill="both", expand=True)
    root.wm_geometry("400x400")
    root.mainloop()
Comment

PREVIOUS NEXT
Code Example
Python :: converting string array to int array python 
Python :: python hsl to rgb 
Python :: conver all dict keys to str python 
Python :: timestamp change python 
Python :: dataframe to list 
Python :: subplot matplotlib set limits 
Python :: telegram markdown syntax 
Python :: how to sum digits of a number in python 
Python :: python os.getenv not working 
Python :: python screen recorder 
Python :: python convert file into list 
Python :: on_ready discord.py 
Python :: python number to array of digits 
Python :: python extract specific columns from pandas dataframe 
Python :: How to find least common multiple of two numbers in Python 
Python :: how to pass header in requests 
Python :: for e in p.event.get(): pygame.error: video system not initialized 
Python :: draw bounding box on image python cv2 
Python :: import excel file to python 
Python :: python hour from datetime 
Python :: discord.py change status 
Python :: pandas read_csv random rows 
Python :: python how to unnest a nested list 
Python :: add self role with discord bot python 
Python :: how to trim mp4 with moviepy 
Python :: click js selenium python 
Python :: how to send audio with inline telebot 
Python :: python - save file 
Python :: how to add numbers in python using for loop 
Python :: ros python publisher 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =