Radiobutton为单选按钮,即在同一组内只能有一个按钮被选中,每当选中组内的一个按钮时,其它的按钮自动改为非选中态,与其他控件不同的是:它有组的概念
不指定绑定变量,每个Radiobutton自成一组
from tkinter import * root = Tk() Radiobutton(root,text = 'python').pack() Radiobutton(root,text = 'tkinter').pack() Radiobutton(root,text = 'widget').pack() root.mainloop()
from tkinter import * root = Tk() #创建一个Radiobutton组,创建三个Radiobutton,并绑定到整型变量v #选中value=1的按钮 v = IntVar() v.set(1) for i in range(3): Radiobutton(root,variable = v,text = 'python',value = i).pack() root.mainloop()
from tkinter import * root = Tk() vLang = IntVar() vOS = IntVar() vLang.set(1) vOS.set(2) for v in [vLang,vOS]: #创建两个组 for i in range(3): #每个组含有3个按钮 Radiobutton(root, variable = v, value = i, text = 'python' + str(i) ).pack() root.mainloop()
from tkinter import * root = Tk() v = IntVar() v.set(1) for i in range(3): Radiobutton(root, variable = v, indicatoron = 0, text = 'python & tkinter', value = i ).pack() root.mainloop()
原文地址:http://blog.csdn.net/a359680405/article/details/45081663