Tkinter Radiobutton
为了实现这个功能,每个单选按钮组必须关联到相同的变量,每一个按钮必须象征着一个单一的值。你可以使用Tab键从一个radionbutton切换到另一个.
语法:
这里是一个简单的语法来创建这个widget:
w = Radiobutton ( master, option, ... )
参数:
master: 这代表了父窗口.
options: 下面是这个小工具最常用的选项列表。这些选项可以作为键 - 值对以逗号分隔.
Option | Description |
---|---|
activebackground | The background color when the mouse is over the radiobutton. |
activeforeground | The foreground color when the mouse is over the radiobutton. |
anchor | If the widget inhabits a space larger than it needs, this option specifies where the radiobutton will sit in that space. The default is anchor=CENTER. |
bg | The normal background color behind the indicator and label. |
bitmap | To display a monochrome image on a radiobutton, set this option to a bitmap. |
borderwidth | The size of the border around the indicator part itself. Default is 2 pixels. |
command | A procedure to be called every time the user changes the state of this radiobutton. |
cursor | If you set this option to a cursor name (arrow, dot etc.), the mouse cursor will change to that pattern when it is over the radiobutton. |
font | The font used for the text. |
fg | The color used to render the text. |
height | The number of lines (not pixels) of text on the radiobutton. Default is 1. |
highlightbackground | The color of the focus highlight when the radiobutton does not have focus. |
highlightcolor | The color of the focus highlight when the radiobutton has the focus. |
image | To display a graphic image instead of text for this radiobutton, set this option to an image object. |
justify | If the text contains multiple lines, this option controls how the text is justified: CENTER (the default), LEFT, or RIGHT. |
padx | How much space to leave to the left and right of the radiobutton and text. Default is 1. |
pady | How much space to leave above and below the radiobutton and text. Default is 1. |
relief | Specifies the appearance of a decorative border around the label. The default is FLAT; for other values. |
selectcolor | The color of the radiobutton when it is set. Default is red. |
selectimage | If you are using the image option to display a graphic instead of text when the radiobutton is cleared, you can set the selectimage option to a different image that will be displayed when the radiobutton is set. |
state | The default is state=NORMAL, but you can set state=DISABLED to gray out the control and make it unresponsive. If the cursor is currently over the radiobutton, the state is ACTIVE. |
text | The label displayed next to the radiobutton. Use newlines ("\n") to display multiple lines of text. |
textvariable | To slave the text displayed in a label widget to a control variable of class StringVar, set this option to that variable. |
underline | You can display an underline (_) below the nth letter of the text, counting from 0, by setting this option to n. The default is underline=-1, which means no underlining. |
value | When a radiobutton is turned on by the user, its control variable is set to its current value option. If the control variable is anIntVar, give each radiobutton in the group a different integer value option. If the control variable is a StringVar, give each radiobutton a different string value option. |
variable | The control variable that this radiobutton shares with the other radiobuttons in the group. This can be either an IntVar or a StringVar. |
width | Width of the label in characters (not pixels!). If this option is not set, the label will be sized to fit its contents. |
wraplength | You can limit the number of characters in each line by setting this option to the desired number. The default value, 0, means that lines will be broken only at newlines. |
方法:
Methods | Description |
---|---|
deselect() | Clears (turns off) the radiobutton. |
flash() | Flashes the radiobutton a few times between its active and normal colors, but leaves it the way it started. |
invoke() | You can call this method to get the same actions that would occur if the user clicked on the radiobutton to change its state. |
select() | Sets (turns on) the radiobutton. |
例子:
自行尝试下面的例子:
from Tkinter import * def sel():
selection = "You selected the option " + str(var.get())
label.config(text = selection) root = Tk()
var = IntVar()
R1 = Radiobutton(root, text="Option 1", variable=var, value=1,
command=sel)
R1.pack( anchor = W ) R2 = Radiobutton(root, text="Option 2", variable=var, value=2,
command=sel)
R2.pack( anchor = W ) R3 = Radiobutton(root, text="Option 3", variable=var, value=3,
command=sel)
R3.pack( anchor = W) label = Label(root)
label.pack()
root.mainloop()
这将产生以下结果:
Tkinter Radiobutton的更多相关文章
- [tkinter]Radiobutton单选按钮的使用
首先因为单选按钮有一个特性(一个被选中后,自动清除其它按钮的选中状态) 所以使用方式也有点不同 错误示例 from tkinter import * root = Tk() r1 = Radiobut ...
- tkinter中Radiobutton单选框控件(七)
Radiobutton控件 由于本次内容中好多知识都是之前重复解释过的,本次就不做解释了.不太清楚的内容请参考tkinter1-6节中的内容 import tkinter wuya = tkinter ...
- tkiner中Radiobutton单选框控件(七)
Radiobutton控件 由于本次内容中好多知识都是之前重复解释过的,本次就不做解释了.不太清楚的内容请参考tkinter1-6节中的内容 import tkinter wuya = tkinter ...
- 基于tkinter的GUI编程
tkinter:tkinter是绑定了Python的TKGUI工具集,就是Python包装的Tcl代码,通过内嵌在Python解释器内部的Tcl解释器实现的,它是Python标准库的一部分,所以使用它 ...
- tkinter python(图形开发界面)
Tkinter模块("Tk 接口")是Python的标准Tk GUI工具包的接口.Tk和Tkinter可以在大多数的Unix平台下使用,同样可以应用在Windows和Macinto ...
- Python -- Gui编程 -- Tkinter的使用 -- 基本控件
1.按钮 tkBtton.py import tkinter root = tkinter.Tk() btn1 = tkinter.Button(root, anchor=tkinter.E,\ te ...
- gui - tkinter 开发
GUI 用户交互界面 tkinter 介绍 tkinter python自带的gui库,对图形图像处理库tk的封装 其他gui:pythonwin,wxpython,pyQT.. 概念介绍 组件:组成 ...
- (转)]PYTHON Tkinter GUI
import Tkinterroot=Tkinter.Tk()label=Tkinter.Label(root,text='hello ,python')label.pack() #将LAB ...
- tkinter python(图形开发界面) 转自:渔单渠
Tkinter模块("Tk 接口")是Python的标准Tk GUI工具包的接口.Tk和Tkinter可以在大多数的Unix平台下使用,同样可以应用在Windows和Macinto ...
随机推荐
- Git 过滤文件,控制上传
在Git的版本控制中,可能有些文件是不需要加入控制的,那我们在提交代码时就需要忽略这些文件,下面讲讲应该怎么给Git配置一些忽略规则. 有三种方法可以忽略掉这些文件,这三种方法都能达到目的,只不过适用 ...
- [译]HIPAA要求的SSL/TLS等级
原文链接:https://luxsci.com/blog/level-ssl-tls-required-hipaa.html 原文发表时间:2015.1.13 本博文仅仅是上述原文的翻译,仅供研究参考 ...
- LOJ2321. 「清华集训 2017」无限之环【费用流】
LINK 很好的一道网络里题 首先想插头DP的还是出门左转10分代码吧 然后考虑怎么网络流 首先要保证没有漏水 也就是说每个接口一定要有对应的接口 那么发现每个点只有可能和上下左右四个点产生联通关系 ...
- JLOI2019游记
JLOI2019游记 DAY -??? 听说是12省联考,好刺激. DAY 1 看题 t1是个lydsy题我还写过博客,t2不会,t3一脸神仙. 这个t3数据好大啊,看到好几个人都用gedit打开大样 ...
- Siddhi cep java 集成简单使用
Siddhi 是一个开源的cep (Complex Event Processing)类库,有一个明显的例子是uber 的事件处理,具体可以google 几张参考cep 以及siddhi 图 java ...
- mui.fire 目标页无法监听到 触发事件
//获得详情页面 if(!detailPage){ detailPage = plus.webview.getWebviewById('detail.html'); } //触发详情页面的newsId ...
- 使用 Excel 可以很方便的做程序原型
使用 Excel 可以很方便的做程序原型 比如计算 单片机的端口模式,可以使用 Excel 很方便的计算出来,花了 15 分钟做好. 还可以使用函数自动根据二进制计算出 十六进制. 然后如果再使用软件 ...
- 【转】VC 线程间通信的三种方式
原文网址:http://my.oschina.net/laopiao/blog/94728 1.使用全局变量(窗体不适用) 实现线程间通信的方法有很多,常用的主要是通过全局变量.自定义消息和 ...
- 关于WCF引用方式之WCF服务寄宿控制台
1.创建解决方案WCFService 依次添加四个项目,如上图,Client和Hosting为控制台应用程序,Service和Service.Interface均为类库. 2.引用关系 Service ...
- git 修改提交说明 commit message
修改最近一次的提交说明 1.代码未推送到远程服务器 $ git commit --amend 此指令会打开文本编辑器,第二行就是提交说明,修改完后按 ctrl+x 退出,后面根据提示操作. 2.代码已 ...