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
  • 相关阅读:
    已开启博客园~
    友链
    javacv 接收RTSP流(或avi/mp4视频文件),输出byte[]
    Springboot项目中,使用logback来管理日志。
    PPT文件流转为图片,并压缩成ZIP文件输出到指定目录
    通过AOP自定义注解实现记录用户操作日志。
    使用javacv,解码socket接收的H264码流(byte[]),转为yuv处理,最后再合成转为H264
    idea 开始java之旅
    浅谈Winform控件开发(一):使用GDI+美化基础窗口
    WinformGDI+入门级实例——扫雷游戏(附源码)
  • 原文地址:https://www.cnblogs.com/Anonytt/p/13885230.html
Copyright © 2011-2022 走看看