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
  • 相关阅读:
    哎~水题,还是最小生成树。没想到一遍AC了...
    博客搬家咯~
    又遇到一个奇葩问题....输出double用%f...
    又想吐槽一下了...同样是DP,差别咋就那么大呢?
    1487: 未覆盖顶点数量.
    并查集~
    侃项目管理 序
    安装Redis报错jemalloc/jemalloc.h: No such file or directory
    PyCharm设置pip国内源(镜像)
    HBase元数据及损坏文件的修复
  • 原文地址:https://www.cnblogs.com/Anonytt/p/13885230.html
Copyright © 2011-2022 走看看