Python tkinter 切换窗口
1 # -*- coding: UTF-8 -*- 2 from tkinter import * 3 4 class MainPages: 5 def __init__(self,master): 6 self.root = master 7 self.root.geometry("600x600") 8 self.fm = '' 9 self.menuBtn() 10 11 def menuBtn(self): 12 btn1 = Button(self.root,text="change",width=10,height=2,activebackground="#c1c1c1", command=lambda:self.change1()) 13 btn1.place(x=0,y=0) 14 btn2 = Button(self.root,text="change2",width=10,height=2,activebackground="#c1c1c1",command=lambda:self.change2()) 15 btn2.place(x=90,y=0) 16 btn3 = Button(self.root,text="change3",width=10,height=2,activebackground="#c1c1c1",command=lambda:self.change3()) 17 btn3.place(x=180,y=0) 18 self.face1() 19 20 def face1(self): 21 self.fm = Frame(self.root,width=300,height=300,bg="skyblue") 22 self.fm.place(x=0,y=50) 23 lbl = Label(self.fm,text="page1") 24 lbl.place(x=0,y=100) 25 26 def face2(self): 27 self.fm = Frame(self.root,width=200,height=200,bg="pink") 28 self.fm.place(x=0,y=50) 29 lbl = Label(self.fm,text="page2") 30 lbl.place(x=0,y=100) 31 32 def face3(self): 33 self.fm = Frame(self.root,width=150,height=150,bg="orange") 34 self.fm.place(x=0,y=50) 35 lbl = Label(self.fm,text="page3") 36 lbl.place(x=0,y=100) 37 38 def change1(self): 39 self.fm.destroy() 40 self.face1() 41 42 def change2(self): 43 self.fm.destroy() 44 self.face2() 45 46 def change3(self): 47 self.fm.destroy() 48 self.face3() 49 50 if __name__ == "__main__": 51 root = Tk() 52 MainPages(root) 53 root.mainloop()