zoukankan      html  css  js  c++  java
  • Tkinter 之Button标签

    一、参数说明

    语法作用
    Button(root,text='xxxx') 按钮图标显示内容
    Button(root,text='xxxx',height=2) 组件的高度(所占行数)
    Button(root,text='xxxx',width=20) 组件的宽度(所占字符个数)
    Button(text='xxxx',fg='blue') 按钮字体颜色
    Button(root,text='xxxx',activebackground='grey') 按钮按下时的前景字体颜色
    Button(root,text=‘xxxxx’,justify=tk.LEFT) 多行文本的对齐方式
    Button(root,text='xxxx',pady=10) 文本上下两侧的空格数
    Button(root,text='xxxx',padx=10) 文本左右两侧的空格数(默认为1)
    Button(root,text='xxxx',command=函数) 按钮触发执行的命令(函数)
    Button(root,text='xxxx',state=tk.DISABLED) 按钮禁止点击
    Button(root,text='xxxx',underline=1) 文字下划线(默认为-1)
    Button(root,text='xxxx',author=tk.CENTER) 文字位置
    Button(root,text='xxxx',textvariable=var) 动态设置文本

    二、代码示例

    import tkinter as tk
    
    window = tk.Tk()
    
    def main():
        global window
        # 设置主窗体大小
        winWidth = 600
        winHeight = 400
        # 获取屏幕分辨率
        screenWidth = window.winfo_screenwidth()
        screenHeight = window.winfo_screenheight()
        # 计算主窗口在屏幕上的坐标
        x = int((screenWidth - winWidth)/ 2)
        y = int((screenHeight - winHeight) / 2)
        
        # 设置主窗口标题
        window.title("Button参数说明")
        # 设置主窗口大小
        window.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y))
        # 设置窗口宽高固定
        window.resizable(0,0)
        # 设置窗口图标
        window.iconbitmap("./image/icon.ico")
        
        """ button参数列表
    
            STANDARD OPTIONS
    
                activebackground, activeforeground, anchor,
                background, bitmap, borderwidth, cursor,
                disabledforeground, font, foreground
                highlightbackground, highlightcolor,
                highlightthickness, image, justify,
                padx, pady, relief, repeatdelay,
                repeatinterval, takefocus, text,
                textvariable, underline, wraplength
    
            WIDGET-SPECIFIC OPTIONS
    
                command, compound, default, height,
                overrelief, state, width
            """
        var = tk.StringVar()
        var.set("提交")
        tk.Button(window, text="提交", width=30, pady=5,fg="#f00", bg="#bbb",
                  borderwidth=0, activeforeground="yellow", activebackground="#666"
                  ,underline=-1, command=click, textvariable=var).pack()
        window.mainloop()
    
    def click():
        print("click")
    
    if __name__ == '__main__':
        main()
    

      

    三、效果图

     

  • 相关阅读:
    wireshark如何抓取本机包
    模拟post请求方法
    Spring Boot中使用RabbitMQ
    Dubbo注册中心的四种配置方式详解
    spring扩展点之三:Spring 的监听事件 ApplicationListener 和 ApplicationEvent 用法,在spring启动后做些事情
    zookeeper 大量连接断开重连原因排查
    分布式一致性协议之:Gossip(八卦)算法
    MongoDB分析工具之一:explain()语句分析工具
    MongoDB分析工具之二:MongoDB分析器Profile
    MySQL安装
  • 原文地址:https://www.cnblogs.com/yang-2018/p/11782686.html
Copyright © 2011-2022 走看看