python如何创建操作页面

444次阅读
没有评论

python如何创建操作页面

1、说明

Python自带tkinter模块,本质上是GUI工具包TK的Python编程界面,提供了快速方便地创建GUI应用的方法。

2、过程

(1)导入tkinter相关的模块。

(2)通过pack()方法定义初始化函数,将组件传递到父容器。

(3)定制创建组件的方法,我们创建一个标签和一个按钮,这个按钮被点击之后,就会触发who方法。

(4)通过messagebox显示提示框。

(5)对APP进行实例化,然后通过主线程监听界面操作。

3、实例

from tkinter import *
import tkinter.messagebox as messagebox
 
class MyApp(Frame):
 
    def __init__(self,master=None):
        Frame.__init__(self,master)
        self.pack()
        self.createWidgets()
 
    def createWidgets(self):
        self.helloLabel = Label(self,text="世界上最帅的人是谁?")
        self.helloLabel.pack()
        self.quitButton = Button(self,text="谁呢?",command=self.who)
        self.quitButton.pack()
 
    def who(self):
        messagebox.showinfo("答案","当然是小帅b啦")
 
myapp = MyApp()
myapp.master.title('hello')
myapp.mainloop()
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2021-04-27发表,共计756字。
新手QQ群:570568346,欢迎进群讨论 Python51学习