RadioButton is a radio button, that is, only one button is selected within the same group, and when one button is selected in the group, the other buttons are automatically changed to unchecked, unlike other controls: It has the concept of a group
1. Create a simple RadioButton
Do not specify binding variables, each RadioButton as a group
From tkinter Import *root = Tk () Radiobutton (root,text = ' python '). Pack () Radiobutton (root,text = ' tkinter '). Pack () Radiobutton (root,text = ' widget '). Pack () Root.mainloop ()
2. Create a RadioButton group and use the binding variable to set the selected button
From tkinter Import *root = Tk () #创建一个Radiobutton组, create three RadioButton, and bind to an integer variable v# select value=1 Button v = Intvar () v.set (1) for I in Range (3): Radiobutton (root,variable = v,text = ' Python ', value = i). Pack () Root.mainloop ()
3. Create two different groups
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 ()
4.Radiobutton Another useful property is Indicatoron, which by default is 1, and if you change this property to 0, its appearance is sunken
From tkinter Import *root = Tk () v = Intvar () v.set (1) for I in Range (3): Radiobutton (root, variable = v, indica Toron = 0, text = ' Python & tkinter ', value = i ). Pack () Root.mainloop ()
Python GUI----Radiobutton