zoukankan      html  css  js  c++  java
  • Tkinter 之RadioButton单选框标签

    一、参数说明

    语法作用
    Radiobutton(root,text='xxxx') 单选框文本显示内容
    Radiobutton(root,variable=color) 单选框索引变量,通过变量的值确定哪个单选框被选中
    Radiobutton(root,variable=color,value='red') 单选框选中时设定变量的值
    Radiobutton(root,variable=color,value='red',command=函数) 单选框选中时执行的命令(函数)
    Radiobutton(root,indicatoron=False) 设置单选框类型(默认为True)

    二、代码示例

    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("RadioButton参数说明")
        # 设置主窗口大小
        window.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y))
        # 设置窗口宽高固定
        window.resizable(0,0)
        # 设置窗口图标
        window.iconbitmap("./image/icon.ico")
        
        """radiobutton参数.
    
            Valid resource names: activebackground, activeforeground, anchor,
            background, bd, bg, bitmap, borderwidth, command, cursor,
            disabledforeground, fg, font, foreground, height,
            highlightbackground, highlightcolor, highlightthickness, image,
            indicatoron, justify, padx, pady, relief, selectcolor, selectimage,
            state, takefocus, text, textvariable, underline, value, variable,
            width, wraplength."""
        
        # 设置默认选中
        v=tk.IntVar()
        v.set(2)
        tk.Radiobutton(window, text="男", font=("Arial", 16), value=2, variable=v, indicatoron=False ).pack()
        tk.Radiobutton(window, text="女", font=("Arial", 16),value=1, variable=v, indicatoron=False ).pack()
        
        window.mainloop()
    
    def click():
        print("click")
    
    if __name__ == '__main__':
        main()
    

      

    三、效果图

  • 相关阅读:
    kuangbin带你飞 并查集 题解
    kuangbin带你飞 最短路 题解
    kuangbin带你飞 后缀数组 题解
    Kuangbin 带你飞-线段树专题 题解
    HDU 4578 Transformation
    Tarjan & LCA 套题题目题解
    Dancing Links [Kuangbin带你飞] 模版及题解
    二分匹配 大白例题虽有代码
    编程范式:响应式编程
    编程结构:Promise和Future
  • 原文地址:https://www.cnblogs.com/yang-2018/p/11783077.html
Copyright © 2011-2022 走看看