首页 > 编程语言 > 详细

Python GUI 05----Checkbutton

时间:2015-04-17 11:40:48      阅读:268      评论:0      收藏:0      [点我收藏+]

1.一个简单的Checkbutton例子

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 = 'check python',command = callCheckbutton).pack()  #不管Checkbutton的状态如何,此回调函数都会被调用
root.mainloop()

3.获取Checkbuton的On与Off的值。默认缺省值分别为1和0

from tkinter import *
root = Tk()
#将一整数与Checkbutton的值绑定,每次点击Checkbutton,将打印出当前的值
v = IntVar()
def callCheckbutton():
    print (v.get())
Checkbutton(root,
            variable = v,
            text = 'checkbutton value',
            command = callCheckbutton).pack()
root.mainloop()

from tkinter import *
root = Tk()
#将一字符串与Checkbutton的值绑定,每次点击Checkbutton,将打印出当前的值
v = StringVar()
def callCheckbutton():
    print v.get()
Checkbutton(root,
            variable = v,
            text = 'checkbutton value',
            onvalue = 'python',                 #设置On的值
            offvalue = 'tkinter',               #设置Off的值
            command = callCheckbutton).pack()
root.mainloop()





Python GUI 05----Checkbutton

原文:http://blog.csdn.net/a359680405/article/details/45081409

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!