Tkinter Checkbutton
您还可以显示在图像代替文字.
语法:
这里是一个简单的语法来创建这个widget:
w = Checkbutton ( master, option, ... )
参数:
master: 这表示父窗口.
options: 下面是这个小工具最常用的选项列表。这些选项可以作为键 - 值对以逗号分隔.
| Option | Description |
|---|---|
| activebackground | Background color when the checkbutton is under the cursor. |
| activeforeground | Foreground color when the checkbutton is under the cursor. |
| bg | The normal background color displayed behind the label and indicator. |
| bitmap | To display a monochrome image on a button. |
| bd | The size of the border around the indicator. Default is 2 pixels. |
| command | A procedure to be called every time the user changes the state of this checkbutton. |
| 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 checkbutton. |
| disabledforeground | The foreground color used to render the text of a disabled checkbutton. The default is a stippled version of the default foreground color. |
| font | The font used for the text. |
| fg | The color used to render the text. |
| height | The number of lines of text on the checkbutton. Default is 1. |
| highlightcolor | The color of the focus highlight when the checkbutton has the focus. |
| image | To display a graphic image on the button. |
| justify | If the text contains multiple lines, this option controls how the text is justified: CENTER, LEFT, or RIGHT. |
| offvalue | Normally, a checkbutton's associated control variable will be set to 0 when it is cleared (off). You can supply an alternate value for the off state by setting offvalue to that value. |
| onvalue | Normally, a checkbutton's associated control variable will be set to 1 when it is set (on). You can supply an alternate value for the on state by setting onvalue to that value. |
| padx | How much space to leave to the left and right of the checkbutton and text. Default is 1 pixel. |
| pady | How much space to leave above and below the checkbutton and text. Default is 1 pixel. |
| relief | With the default value, relief=FLAT, the checkbutton does not stand out from its background. You may set this option to any of the other styles |
| selectcolor | The color of the checkbutton when it is set. Default is selectcolor="red". |
| selectimage | If you set this option to an image, that image will appear in the checkbutton when it is set. |
| state | The default is state=NORMAL, but you can use state=DISABLED to gray out the control and make it unresponsive. If the cursor is currently over the checkbutton, the state is ACTIVE. |
| text | The label displayed next to the checkbutton. Use newlines ("\n") to display multiple lines of text. |
| underline | With the default value of -1, none of the characters of the text label are underlined. Set this option to the index of a character in the text (counting from zero) to underline that character. |
| variable | The control variable that tracks the current state of the checkbutton. Normally this variable is an IntVar, and 0 means cleared and 1 means set, but see the offvalue and onvalue options above. |
| width | checkbutton的默认宽度取决于所显示的图像或文字的大小。您可以设置此选项的字符数和checkbutton的,总是有许多字符的空间. |
| wraplength | Normally, lines are not wrapped. You can set this option to a number of characters and all lines will be broken into pieces no longer than that number. |
方法:
以下是这个小工具的常用方法:
| Medthod | Description |
|---|---|
| deselect() | Clears (turns off) the checkbutton. |
| flash() | Flashes the checkbutton 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 checkbutton to change its state. |
| select() | Sets (turns on) the checkbutton. |
| toggle() | Clears the checkbutton if set, sets it if cleared. |
例子:
自行尝试下面的例子:
from Tkinter import *
import tkMessageBox
import Tkinter top = Tkinter.Tk()
CheckVar1 = IntVar()
CheckVar2 = IntVar()
C1 = Checkbutton(top, text = "Music", variable = CheckVar1, \
onvalue = 1, offvalue = 0, height=5, \
width = 20)
C2 = Checkbutton(top, text = "Video", variable = CheckVar2, \
onvalue = 1, offvalue = 0, height=5, \
width = 20)
C1.pack()
C2.pack()
top.mainloop()
这将产生以下结果:
Tkinter Checkbutton的更多相关文章
- tkinter中checkbutton多选框控件和variable用法(六)
checkbutton控件 简单的实现多选: import tkinter wuya = tkinter.Tk() wuya.title("wuya") wuya.geometry ...
- 基于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 ...
- python之tkinter入坑Pack()------(1)
tkinter 的pack()可以设置的属性如下: pack_configure(self, cnf={}, **kw)Pack a widget in the parent widget. Use ...
- python中的Tkinter模块
Tkinter模块("Tk 接口")是Python的标准Tk GUI工具包的接口.Tk和Tkinter可以在大多数的Unix平台下使用,同样可以应用在Windows和Macinto ...
随机推荐
- 前端自动化之sass实时编译及自动刷新浏览器
gulp livereload实现sass实时编译及浏览器自动刷新 首先gulp是基于Node的,所以确保你已经安装 node.js,在Nodejs官方网站下载跟自己操作系统相对应的安装包. 先说一下 ...
- vps上搭建jupyter notebook远程服务
安装anaconda 使用如下命令下载: wget https://repo.continuum.io/archive/Anaconda3-5.0.0.1-Linux-x86_64.sh 如果非roo ...
- 树形DP新识
HihoCoder: 1041(点) 1063(边) 1035(边) HDU1520 (签到) HDU2415(emm) 目前我遇到的树形DP有两类: ∂:点处理,大概就是点的乱搞,比如找一些点,这些 ...
- Map集合学习
Java中常用的Map实现类主要有:HashMap.HashTable.TreeMap.LinkedHashMap. 一:HashMap HashMap介绍 HashMap的底层其实是“链表的数组”, ...
- 【DUBBO】Dubbo原理解析-服务发布
转载:http://blog.csdn.net/quhongwei_zhanqiu/article/details/41651205 服务发布方在spring的配置文件中配置如下: <bean ...
- cmd连接mysql操作命令
连接:mysql -h主机地址 -u用户名 -p用户密码 (注:u与root可以不用加空格,其它也一样)断开:exit (回车) 创建授权:grant select on 数据库.* to 用户名@登 ...
- sqlopsstudio 微软开源跨平台sql server 连接工具
sqlopsstudio 微软开源的sql server 连接工具,跨平台,基于vscode 分之代码. 项目地址: https://github.com/Microsoft/sqlopsstudi ...
- iOS7 自己定义动画跳转
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/Liar0606/article/details/26399125 简单介绍 在iOS7系统中,假设你 ...
- Docker生态会重蹈Hadoop的覆辙吗?
从网上找到了这篇2016年中旬刷爆朋友圈的文章,没有找到作者和首发出处.两年多过去了,文中分析的很多不确定性都有了结论,里面不少分析思路.观点还是很不错的. Docker的兴起和Hadoop何其相似 ...
- [深度学习]Wake-Sleep算法
本文翻译自2007-To recognize shapes, first learn to generate images, Geoffrey Hinton. 第五种策略的设计思想是使得高层的特征提取 ...