zoukankan      html  css  js  c++  java
  • python_GUI测试用

    经典的面向对象写法:

    """测试一个经典的GUI程序的学法,使用面向对象的方式"""
    from tkinter import *
    from tkinter import messagebox
    class Application(Frame):
        """一个经典的GUI程序的类的写法"""
        def __init__(self, master=None):
            super().__init__(master) #super代表父类的定义,而不是父类的对象
            self.master=master
            self.pack()
            self.createWidget()
    
        def createWidget(self):
            """创建组件"""
            self.btn01 = Button(self)
            self.btn01["text"] = "点击送花"
            self.btn01.pack()
            self.btn01["command"] = self.songhua
    
            self.btn02 = Button(self)
            self.btn02["text"] = "点击关注"
            self.btn02.pack()
            self.btn02["command"] = self.libm
    
            #创建一个退出按钮
            self.btnQuit = Button(self,text="退出",command=root.destroy)
            self.btnQuit.pack()
    
        def songhua(self):
            messagebox.showinfo("送花","送你99朵玫瑰花")
        def libm(self):
            messagebox.showinfo("limb","李逼姆")
    if __name__ == '__main__':
        root = Tk()
        root.geometry("400x100+200+300")
        root.title("一个经典的GUI程序类的测试")
        app = Application(master=root)
        root.mainloop()
    View Code

    label用法

    """测试一个经典的GUI程序的学法,使用面向对象的方式"""
    from tkinter import *
    from tkinter import messagebox
    class Application(Frame):
        """一个经典的GUI程序的类的写法"""
        def __init__(self, master=None):
            super().__init__(master) #super代表父类的定义,而不是父类的对象
            self.master=master
            self.pack()
            self.createWidget()
    
        def createWidget(self):
            """创建组件"""
            self.label01 = Label(self,text="百战程序员",width=10,height=2,
                                 bg="black",fg="white")
            self.label01.pack()
    
            self.label02 = Label(self,text="郑益天才",width=10,height=2,
                                 bg="blue",fg="white",font=("黑体",30))
            self.label02.pack()
    
            self.label03 = Label(self,text="AAAA
    BBB
    CCC",
                                 borderwidth=5,relief="solid",justify="left")
            self.label03.pack()
    if __name__ == '__main__':
        root = Tk()
        root.geometry("400x200+200+300")
        root.title("一个经典的GUI程序类的测试")
        app = Application(master=root)
        root.mainloop()
    View Code
  • 相关阅读:
    积跬步,聚小流------关于UML类图
    深度学习 Deep Learning UFLDL 最新 Tutorial 学习笔记 1:Linear Regression
    数字语音信号处理学习笔记——语音信号的短时频域分析(2)
    PHP程序猿必须学习的第二课——站点安全问题预防
    Connection for controluser as defined in your configuration failed.
    NYOJ 76 超级台阶
    单片机小白学步系列(十) 单片机程序下载相关知识
    SQL 语言划分
    UVA 11754
    客户端远程方法声明
  • 原文地址:https://www.cnblogs.com/Anonytt/p/13885230.html
Copyright © 2011-2022 走看看