Python tkinter 切换窗口
2022/6/2 1:22:00
本文主要是介绍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, command=lambda:self.change1()) 13 btn1.place(x=0,y=0) 14 btn2 = Button(self.root,text="change2",width=10,height=2,command=lambda:self.change2()) 15 btn2.place(x=90,y=0) 16 btn3 = Button(self.root,text="change3",width=10,height=2,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()
这篇关于Python tkinter 切换窗口的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-26Python基础编程
- 2024-11-25Python编程基础:变量与类型
- 2024-11-25Python编程基础与实践
- 2024-11-24Python编程基础详解
- 2024-11-21Python编程基础教程
- 2024-11-20Python编程基础与实践
- 2024-11-20Python编程基础与高级应用
- 2024-11-19Python 基础编程教程
- 2024-11-19Python基础入门教程
- 2024-11-17在FastAPI项目中添加一个生产级别的数据库——本地环境搭建指南