python的GUI编程(Tkinter库)(二)
2017-06-14 10:53
609 查看
单选按钮
单选按钮是一组排他性的选择框,只能从该组中选择一个选项,当选择了其中一个后,变回取消其他的选项的选择必选将一组单选按钮与一个相同的变量关联起来,有用户选择不同的值
示例:
root=Tk() root.title('top') foo=IntVar() for text,value in[('red',1),('green',2),('black',3),('blue',4),('yellow',5)]: r=Radiobutton(root,text=text,value=value,variable=foo) r.pack(anchor=W) foo.set(2) root.mainloop()
结果:
Radiobutton组件额参数
varible 单选索引变量,通过变量的值确定哪个单选按钮被选中,一组单选按钮使用同一个索引变量value 单选按钮选中时变量的值
command 单选按钮选中时执行的命令
复选按钮(Checkbutton)
每一按钮都需要与一个变量相关联,且每一个复选按钮关联的变量都是相同的,若像单选按钮一样,关联的时同一个按钮,则选中一个的时候,会将所有的按钮都选上,可以给每个复选按钮绑定一个回调,当该选项被选中时,执行该回调示例:
from Tkinter import * root=Tk() root.title('top') l=[('red',1),('green',2),('black',3),('blue',4),('yellow',5)] for text,value in l: foo=IntVar() c=Checkbutton(root,text=text,variable=foo) c.pack(anchor=W) root.mainloop()
结果:
示例2:禁用状态下的复选窗口
from Tkinter import * root=Tk() root.title('top') L=[('red',1,NORMAL),('green',2,NORMAL),('black',3,DISABLED),('blue',4,NORMAL),('yellow',5,DISABLED)] for text,value,status in L: foo=IntVar() r=Checkbutton(root,text=text,variable=foo,state=status) r.pack(anchor=W) root.mainloop()
结果:
Checkbutton组件参数
variable 复选按钮索引变量,通过变量的值确定哪些复选按钮被选中,每个复选按钮使用不同的变量,使复选按钮之间相互独立onvalue 复选按钮选中时变量的值
offvalue 复选按钮为被选中时的变量的值
command 复选按钮选中时执行的命令
相关文章推荐
- [Python]核心编程之GUI编程(Tkinter)
- Python Tkinter GUI编程入门介绍
- Stage5--Python GUI编程TKinter
- python学习笔记——Tkinter GUI编程——简介
- 关于python GUI编程(Tkinter) 创建子窗口及在窗口上用图片绘图
- python学习笔记——Tkinter GUI编程——简介
- Python GUI编程(Tkinter)
- python GUI编程(Tkinter)
- Python GUI编程--Tkinter
- Python GUI tkinter编程
- Python GUI编程(Tkinter)
- Python GUI编程(Tkinter)
- python的GUI编程之Tkinter
- 使用Tkinter做python的GUI编程
- Python -- Gui编程 -- Tkinter的使用 -- 对话框消息框
- Python Tkinter GUI编程入门介绍
- Python GUI编程(Tkinter)
- Python下用Tkinter进行GUI编程
- python GUI编程(Tkinter)
- Python -- Gui编程 -- Tkinter的使用 -- 对话框消息框