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
  • 相关阅读:
    Linux安装RabbitMQ3.8.7
    VS安装Resharper,使用IDEA风格的快捷键,还需修改的快捷键
    Spring Boot Starter开发
    windows安装redis集群
    spring为bean指定InitMethod和DestroyMethod的三种方法
    spring注入的方式总结
    bean运行时值注入
    CodeForces 1569C Jury Meeting
    CodeForces 1569B Chess Tournament
    CodeForces 1569A Balanced Substring
  • 原文地址:https://www.cnblogs.com/Anonytt/p/13885230.html
Copyright © 2011-2022 走看看