python如何创建操作页面
发布时间:2024-08-08 16:06:05

说明
Python自带tkinter模块,本质上是GUI工具包TK的Python编程界面,为创建GUI应用提供了快速方便的方法。
过程
(1)导入tkinter相关模块。
(2)通过pack()定义初始化函数,将组件传输到父容器。
(3)定制创建组件的方法,我们创建一个标签和一个按钮,点击后触发who方法。
(4)通过messagebox显示提示框。
(5)实例化APP,然后通过主线程监控界面操作。
实例
fromtkinterimport*
importtkinter.messageboxasmessagebox
classMyApp(Frame):
def__init__(self,master=None):
Frame.__init__(self,master)
self.pack()
self.createWidgets()
defcreateWidgets(self):
self.helloLabel=Label(self,text="谁是世界上最帅的人?")
self.helloLabel.pack()
self.quitButton=Button(self,text="谁呢?",command=self.who)
self.quitButton.pack()
defwho(self):
messagebox.showinfo("答案","当然是小帅B")
myapp=MyApp()
myapp.master.title('hello')
myapp.mainloop()以上是python创建操作页面的方法,希望对大家有所帮助。更多Python学习指导:基础教程python基础教程
本文教程操作环境:windows7系统Python 3.9.1,DELL G3电脑。
下一篇 Python代码中编译是什么
