Checkbutton
#tkinter之Checkbutton篇
#Checkbutton又称为多选按钮,可以表示两种状态,On和Off,可以设置回调函数,每当点击此按钮时回调函数被调用。
1、一个简单的Checkbutton例子
#创建一个Checkbutton,显示文本为'python'
from tkinter import * root = Tk()
Checkbutton(root,text='python').pack()
root.mainloop()
2、设置Checkbutton的回调函数
from tkinter import * def callCheckbutton():
print('you check this button') root = Tk()
Checkbutton(root,text='chech python',command=callCheckbutton).pack()
root.mainloop()
#不管Checkbutton的状态如何,此回调函数都会被调用,即对话框你选或者不选,只要有点击,就会调用函数
3、通过回调函数改变Checkbutton的显示文本text的值
from tkinter import * def callCheckbutton():
#改变v的值,即改变Checkbutton的显示值
v.set('Check Tkinter') root = Tk()
v = StringVar()#声明v是tkinter里面的一个字符串变量
v.set('good good')#设定字符串变量v的值
#绑定v到Checkbutton的属性textvariable
Checkbutton(root,textvariable =v,command=callCheckbutton).pack()
root.mainloop()
4、上述的textvariable使用方法与Button的用法完全相同,使用此例是为了区别Checkbutton的另外一个属性variable,此属性与textvariable不同,
它是与这个控件本身绑定,checkbutton本身有值,On与Off分别为1和0,
也就是说,variable的值是Checkbutton本身的值,是0或1等其他类型的数值
textvariable是里面显示的文本的值
#显示Checkbutton的值
from tkinter import *
root =Tk()
#将一整数与Checkbutton的值绑定,每次点击Checkbutton,将打印当前的值
v = IntVar()#声明v是tkinter里面的一个整形变量 Checkbutton(root,variable = v,text ='checkbutton value').pack()
Label(root,textvariable = v).pack() root.mainloop()
5、Checkbutton的值不仅仅是1或者0,可以是其他类型的数值,可以通过onvalue,offvalue属性设置状态值
如下代码将On设置为python,Off设置为tkinter,程序打印值将不再是0或者1,而是tkinter和python
from tkinter import *
root = Tk()
#将一字符串与Checkbutton的值绑定,每次点击Checkbutton将打印出当前的值
v = StringVar()#声明v是tkinter里面的字符串变量
def callCheckbutton():
print(v.get()) Checkbutton(root,variable = v,text = 'checkbutton value',onvalue = 'python',offvalue='tkinter',command=callCheckbutton).pack()
root.mainloop()
Checkbutton的更多相关文章
- Tkinter教程之Checkbutton篇
本文转载自:http://blog.csdn.net/jcodeer/article/details/1811306 #Tkinter教程之Checkbutton篇#Checkbutton又称为多选按 ...
- Checkbutton 和 Radiobutton
The Checkbutton widget is used to display a number of options to a user as toggle buttons. The user ...
- Chapter 4. Button, Checkbutton, and Radiobutton Widgets 按钮,复选按钮,单选按钮
Chapter 4. Button, Checkbutton, and Radiobutton Widgets 按钮,复选按钮,单选按钮 几乎所有的Perl/Tk 应用使用按钮以这样或者那样的方式 ...
- tkinter第三章(单选和多选)RadioButton CheckButton
最简单的CheckButton多选类 import tkinter as tk #checkButton的内容,多选 root = tk.Tk() v = tk.IntVar()#装整形变量的 #va ...
- tkinter中checkbutton多选框控件和variable用法(六)
checkbutton控件 简单的实现多选: import tkinter wuya = tkinter.Tk() wuya.title("wuya") wuya.geometry ...
- Python3 tkinter基础 Checkbutton variable 多选钮是否被选中
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- tkinter学习系列之(五)Checkbutton控件
目录 目录 前言 (一)基本属性 (二)案例 1.简单的复选框 2.组合复选框 目录 前言 复选框:可以同时多选的一组框,其只有两种状态,选中与未选中. (一)基本属性 (1)说明: tkinter里 ...
- Python3 tkinter基础 Checkbutton anchor for生成多个控件并西对齐
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- DevExpress09、SimpleButton、CheckButton、DropDownButton、HScrollBar控件和VScrollBar控件
SimpleButton控件 使用SimpleButton控件, 创建一个Button按钮, 可以通过其Image属性添加图片: 该控件与WinForm自带的Button按钮类似: 效果如下: Che ...
随机推荐
- call of overloaded 'xxx' is ambiguous
这里定义了一个模版函数,功能同STL里的copy函数: #include <vector> #include <list> #include <iostream> ...
- 使用selenium时提示:ImportError:No module named selenium
问题分析: 用的是mac系统,已经通过sudo pip install -U selenium安装好了selenium, 但是无论用命令行还是用sublime导入selenium都会提示错误. 于是查 ...
- 如何使用 RESTClient 调试微信支付接口
我们知道微信支付使用http协议进行api调用,body 使用xml格式,使用的一般http在线调试工具,无法进行xml数据的post. RESTClient 做的很好,支持各种http 方法,bod ...
- 云服务器Windows Server2012 配置http服务器(又称Web服务器,IIS)
出错:无法打开运行空间池.服务器管理器WinRM插件可能已损坏或丢失. 解决方法: http://shiyousan.com/post/636308065767125916 第一步是开启WinRM服务 ...
- Linux下的进程与线程(二)—— 信号
Linux进程之间的通信: 本文主要讨论信号问题. 在Linux下的进程与线程(一)中提到,调度器可以用中断的方式调度进程. 然而,进程是怎么知道自己需要被调度了呢?是内核通过向进程发送信号,进程才得 ...
- 蓝桥杯java历年真题及答案整理1~20.md
蓝桥杯java历年真题及答案整理(闭关一个月,呕心沥血整理出来的) 1 算法是这样的,如果给定N个不同字符,将这N个字符全排列,最终的结果将会是N!种.如:给定 A.B.C三个不同的字符,则结果为:A ...
- Java基础学习笔记十 Java基础语法之final、static、匿名对象、内部类
final关键字 继承的出现提高了代码的复用性,并方便开发.但随之也有问题,有些类在描述完之后,不想被继承,或者有些类中的部分方法功能是固定的,不想让子类重写.可是当子类继承了这些特殊类之后,就可以对 ...
- Go语言标准库_输入/输出
Go语言标准库_输入/输出 转载节选自<Go语言标准库> Reader 接口 type Reader interface { Read(p []byte) (n int, err erro ...
- Beta第四天
听说
- 第一周C语言作业
一.PTA实验作业 题目1.温度转换 1.实验代码 int main() { int fahr = 150,celsius; celsius = 5 * (fahr - 32) / 9; printf ...