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()
    

      

    三、效果图

  • 相关阅读:
    ASP.NET MVC : 实现我们自己的视图引擎
    [转] 理解 JavaScript 闭包
    郁闷的disabled
    ASP.NET MVC 使用Post, Redirect, Get (PRG)模式
    获取窗口 高 、宽 的JS代码
    javaScript 中的return和return false
    一种标记是否为AJAX异步请求的思路
    ASP.NET MVC 源码更新预览
    [译]用Visual Studio2012来开发SQL Server 2012商业智能项目
    玩玩Windows Azure
  • 原文地址:https://www.cnblogs.com/yang-2018/p/11783077.html
Copyright © 2011-2022 走看看