zoukankan      html  css  js  c++  java
  • Tkinter 之CheckButton复选框标签

    一、参数说明

    语法作用
    Checkbutton(root,text='xxxx') 复选框显示的文本
    Checkbutton(root,variable=id) 通过变量的值确定哪些复选框被选中
    Checkbutton(root,variable=id,onvalue=1) 复选框选中(有效)时变量的值
    Checkbutton(root,variable=id,onvalue=1,offvalue=0) 复选框未选中(无效)时变量的值
    Checkbutton(root,variable=id,onvalue=1,offvalue=0,command=函数) 复选框选中时执行的命令(函数)

    二、代码示例

    import tkinter as tk
    
    window = tk.Tk()
    
    def main():
        global window
        window.title("CheckButton参数说明")
        winWidth = 600
        winHeight = 400
        # 获取屏幕宽高
        screenWidth = window.winfo_screenwidth()
        screenHeight = window.winfo_screenheight()
        
        x = int((screenWidth - winWidth) / 2)
        y = int((screenHeight - winHeight) / 2)
        # 设置窗口居中
        window.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y))
        window.iconbitmap("./image/icon.ico")
        
        """checkbutton参数.
    
            Valid resource names: activebackground, activeforeground, anchor,
            background, bd, bg, bitmap, borderwidth, command, cursor,
            disabledforeground, fg, font, foreground, height,
            highlightbackground, highlightcolor, highlightthickness, image,
            indicatoron, justify, offvalue, onvalue, padx, pady, relief,
            selectcolor, selectimage, state, takefocus, text, textvariable,
            underline, variable, width, wraplength."""
        var1 = tk.IntVar()
        var2 = tk.IntVar()
        tk.Checkbutton(window, text="篮球", onvalue=1, offvalue=0,
                       variable=var1, command=callBack, activebackground="#f00",
                       foreground="#666").pack()
        tk.Checkbutton(window, text="足球", onvalue=1, offvalue=0,
                       variable=var2, command=callBack, activebackground="#f00",
                       foreground="#bbb").pack()
        window.mainloop()
        
    def callBack():
        print(1)
    if __name__ == '__main__':
        main()
    

      

    三、效果图

  • 相关阅读:
    [Swift]GZip字符串压缩和解压缩(Java/C#通用)
    [XCode]UI测试/单元测试
    转 oracle apex 使用
    转 pygame学习笔记(1)——安装及矩形、圆型画图
    转 11g RAC R2 体系结构---Grid
    转如何升级oracle版本?(11.2.0.1至11.2.0.4)
    ORA-14074: partition bound must collate higher than that of the last partition
    12c pdb expdp use DATA_PUMP_DIR meet ORA-39145
    转【Python】Python-skier游戏[摘自.与孩子一起学编程]
    Dock
  • 原文地址:https://www.cnblogs.com/yang-2018/p/11784892.html
Copyright © 2011-2022 走看看