首页 > 其他 > 详细

tkinter checkbutton 第一节

时间:2017-09-23 19:43:49      阅读:335      评论:0      收藏:0      [点我收藏+]

>>> from tkinter import *
>>> from tkinter import ttk
>>> root=Tk()
>>> checkbutton=ttk.Checkbutton(root,text="ABCD!")  #创建一个二选框。框子的名字是ABCD
>>> checkbutton.pack()                                                 #排版
>>> spam=StringVar()              #新建一个变量spam,变量是StringVar()类型                                                   
>>> spam.set(‘SILENCE‘)             #设置spam的值为“SILENCE”

>>> spam.get()                 #通过spam的get方法得到spam的值
‘SILENCE‘
>>> checkbutton.config(variable=spam,onvalue="Nevermore",offvalue="snippet")    #configcheckbutton,variable项目用spam变量。意思就是当二选框选中的时候。spam的名字是Nevermore。 没选中的时候spam的名字是snippet
>>> spam.get() #默认时候返回SILENCE
‘SILENCE‘
>>> spam.get()  #选中时候返回Nevermore
‘Nevermore‘
>>> spam.get()  
‘Nevermore‘
>>> spam.get() #取消勾选返回值是snippet
‘snippet‘
>>> breakfast=StringVar()   #新建一个breakfast的变量。变量类型是StringVar()
>>> ttk.Radiaobutton(root,text="SPAM",variable=breakfast,value="SPAM").pack()   #新建一个圆的复选框。内容显示为SPAM,variable绑定未breakfast,选中这个时候breakfast。value就是SPAM

Traceback (most recent call last):
File "<pyshell#149>", line 1, in <module>
ttk.Radiaobutton(root,text="SPAM",variable=breakfast,value="SPAM").pack()
AttributeError: module ‘tkinter.ttk‘ has no attribute ‘Radiaobutton‘
>>> ttk.Radiobutton(root,text="SPAM",variable=breakfast,value="SPAM").pack()
>>> ttk.Radiobutton(root,text="Eggs",variable=breakfast,value="e").pack()
>>> ttk.Radiobutton(root,text="Sausage",variable=breakfast,value="Sausage").pack()
>>> ttk.Radiobutton(root,text="Onion",variable=breakfast,value="Onion").pack()
>>> breakfast.get()
‘SPAM‘
>>> breakfast.get()
‘e‘
>>>

 

技术分享

tkinter checkbutton 第一节

原文:http://www.cnblogs.com/uxiuxi/p/7581925.html

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