Python - Tkinter Checkbutton: checkbutton小部件用于显示切换按钮的用户多项选择。然后,用户可以通过点击相应的按钮每个选项中选择一个或多个选项.
 
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的更多相关文章

  1. tkinter中checkbutton多选框控件和variable用法(六)

    checkbutton控件 简单的实现多选: import tkinter wuya = tkinter.Tk() wuya.title("wuya") wuya.geometry ...

  2. 基于tkinter的GUI编程

    tkinter:tkinter是绑定了Python的TKGUI工具集,就是Python包装的Tcl代码,通过内嵌在Python解释器内部的Tcl解释器实现的,它是Python标准库的一部分,所以使用它 ...

  3. tkinter python(图形开发界面)

    Tkinter模块("Tk 接口")是Python的标准Tk GUI工具包的接口.Tk和Tkinter可以在大多数的Unix平台下使用,同样可以应用在Windows和Macinto ...

  4. Python -- Gui编程 -- Tkinter的使用 -- 基本控件

    1.按钮 tkBtton.py import tkinter root = tkinter.Tk() btn1 = tkinter.Button(root, anchor=tkinter.E,\ te ...

  5. gui - tkinter 开发

    GUI 用户交互界面 tkinter 介绍 tkinter python自带的gui库,对图形图像处理库tk的封装 其他gui:pythonwin,wxpython,pyQT.. 概念介绍 组件:组成 ...

  6. (转)]PYTHON Tkinter GUI

    import Tkinterroot=Tkinter.Tk()label=Tkinter.Label(root,text='hello ,python')label.pack()      #将LAB ...

  7. tkinter python(图形开发界面) 转自:渔单渠

    Tkinter模块("Tk 接口")是Python的标准Tk GUI工具包的接口.Tk和Tkinter可以在大多数的Unix平台下使用,同样可以应用在Windows和Macinto ...

  8. python之tkinter入坑Pack()------(1)

    tkinter 的pack()可以设置的属性如下: pack_configure(self, cnf={}, **kw)Pack a widget in the parent widget. Use  ...

  9. python中的Tkinter模块

    Tkinter模块("Tk 接口")是Python的标准Tk GUI工具包的接口.Tk和Tkinter可以在大多数的Unix平台下使用,同样可以应用在Windows和Macinto ...

随机推荐

  1. JMter中添加断点和关联

    一.            断点 断言是什么呢,它是用来检查返回结果对不对的. 用来验证结果是否正确,如果正确的话,就代表这个请求的返回是正确的,如果没有的话就代表这个请求的结果和我们预期的不一致,这 ...

  2. sql server不能删除数据库,显示错误:正在使用

    解决办法: use mastergoalter database database_name set single_user with rollback immediate --将数据库回滚到原始配置 ...

  3. 【数据处理】OneHotEncoder编码

    原创博文,转载请注明出处! # OneHotEncoder编码      OneHotEncoder编码称为"哑编码"或"独热编码",是将表示分类的数据扩维度, ...

  4. Java并发--ConcurrentModificationException(并发修改异常)异常原因和解决方法

    在前面一篇文章中提到,对Vector.ArrayList在迭代的时候如果同时对其进行修改就会抛出java.util.ConcurrentModificationException异常.下面我们就来讨论 ...

  5. 二次剩余-Cipolla

    二次剩余 \(Cipolla\) 算法 概述 大概就是在模 \(p\) 意义下开根号,如求解方程\(x^2\equiv n(mod\ p)\). 这里只考虑 \(p\) 为素数的情况.若 \(p=2\ ...

  6. WebLogic配置JNDI数据源

    一.什么是jndi数据源 JNDI是Java命名与目录接口(Java Naming and Directory Interface),在J2EE规范中是重要的规范之一. 我们平时开发web程序的时候, ...

  7. A Corrupt Mayor's Performance Art

    Corrupt governors always find ways to get dirty money. Paint something, then sell the worthless pain ...

  8. python 打印对象所有属性值

    from pprint import pprint pprint (vars(your_object)) 另外查看所有属性名用.__dict__

  9. Linux驱动开发基础知识

    常用命令 lsmod: list module,将模块列表显示),功能是打印出当前内核中已经安装的模块列表 insmod: install module,安装模块,功能是向当前内核中去安装一个模块,用 ...

  10. 关于git的基本使用

    参考:http://www.cnblogs.com/mengdd/p/3585038.html