web123456

tkinter implements page switching

import tkinter as tk class Index(tk.Frame): def __init__(self,parent=None): super().__init__(parent) self.pack(expand=1,fill="both") self.frame_left = tk.Frame(self) self.frame_left.pack(side='left',expand=1,fill="x",padx=5,pady=5) #Three buttons are used to switch pages for i in ["Increase","delete","Revoke"]: but = tk.Button(self.frame_left,text=i) but.pack(side='top',expand=1,fill="y") but.bind("<Button-1>",self.change) # Used to host the page content of the switch self.frame_right=tk.Frame(self) self.frame_right.pack(side='left',expand=1,fill="both",padx=5,pady=5) lab = tk.Label(self.frame_right,text="I'm the first page") lab.pack() #Switch page according to the left mouse click event def change(self,event): res = event.widget["text"] for i in self.frame_right.winfo_children(): i.destroy() if res == "Increase": Page1(self.frame_right) elif res == "delete": Page2(self.frame_right) elif res == "Revoke": Page3(self.frame_right) class Page1(tk.Frame): def __init__(self,parent=None): super().__init__(parent) self.pack(expand=1,fill="both") tk.Label(self,text="I am page1").pack() class Page2(tk.Frame): def __init__(self,parent=None): super().__init__(parent) self.pack(expand=1,fill="both") tk.Label(self,text="I'm page2").pack() class Page3(tk.Frame): def __init__(self,parent=None): super().__init__(parent) self.pack(expand=1,fill="both") tk.Label(self,text="I'm page3").pack() if __name__ == "__main__": root = tk.Tk() root.title("Interface Demo") index = Index(root) root.mainloop()