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

  

三、效果图

原文地址:https://www.cnblogs.com/yang-2018/p/11783077.html

时间: 2024-08-30 03:53:28

Tkinter 之RadioButton单选框标签的相关文章

WPF中单选框RadioButton

单选框RadioButton的基本使用: <StackPanel Margin="10"> <Label FontWeight="Bold">Are you ready?</Label> <RadioButton>Yes</RadioButton> <RadioButton>No</RadioButton> <RadioButton IsChecked="True&q

学习15 单选框/多选框标签

<!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <title>单选框/复选框</title> </head> <body> <form action="save.php" method="p

可分组的选择框控件(MVVM下)(Toggle样式 仿造单选框RadioButton,复选框CheckBox功能)

原地址: http://www.cnblogs.com/yk250/p/5660340.html 效果图如下:支持分组的单选框,复选框样式和MVVM下功能的实现.这是项目中一个快捷键功能的扩展. 1,准备工作:VS2015 (15对WPF的支持变得异常的好,调试模式下允许自动更改属性.),随VS发布的Blend,几个基础类: 1 public class RelayCommand : ICommand 2 { 3 #region Fields 4 5 readonly Action<object

label标签(实现单选框点字也能选中)

性别单选框: 原文地址:https://www.cnblogs.com/jihongtao/p/10291234.html

[CSS揭秘]自定义单选框和复选框

很多Web前端工程师肯定都会遇到过,在项目中,UI设计师跑来跟你说,我这个地方的表单控件需要设计成这个样子那个样子.但是用CSS却不能够修改这些控件的默认样式,于是乎,只能通过div+javascript技术来进行模拟.特别是在如今移动端的崛起时代,更加注重用户的体验.于是就更加需要这样一种hack技术. 如果对如今的前端框架有过了解,都会知道组件这个概念.那么在这些框架中,都会提供一些单选框或复选框按钮组件.可见大家之前受到表单元素的默认样式的毒害有多深. 今天先给大家简单介绍一下如何通过CS

vue.js实现单选框、复选框和下拉框

Vue.js可以很方便的实现数据双向绑定,所以在处理表单,人机交互方面具有很大的优势.下边以单选框.复选框和下拉框为例介绍他们在HTML和Vue.js中的具体实现方式. 一.单选框 在传统的HTML中实现单选框的方法如下: <div id="app"> <input type="radio" name="gender" value="man" id="man"/><label

单选框与复选框的实现

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.hanqi.test5"> <application android:allowBackup="true" android:icon=&q

android 单选框和复选框

<?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_heig

android开发入门之单选框的基本应用

随着android手机越来越火,android操作系统也深受开发者的喜爱,很多程序员慢慢转行做android开发.今天麦子学院的android开发老师给大家讲讲android单选框基本应用,今天我们跟着麦子学院android老师学习Android单选框的实现方式. ●使用Android单选框的时候,要用RadioGroup来分组 ●选择RadioGroup里的单选框的时候,将调用RadioGroup的Check·()方法 ●追加单选框被选择时处理的时候, 1.调用setOnCheckedChan