1.单选框
①声明与初始化
import tkinter
import tkinter.messagebox
import tkinter.ttk
labelSex = tkinter.Label(root, text='Sex:', justify=tkinter.RIGHT, width=50)
labelSex.place(x=10, y=70, width=50, height=20)
#与性别关联的变量,1:男;0:女,默认为男
sex = tkinter.IntVar()
sex.set(1)
#单选钮,男
radioMan = tkinter.Radiobutton(root,variable=sex,value=1,text='Man')
radioMan.place(x=70, y=70, width=50, height=20)
#单选钮,女
radioWoman = tkinter.Radiobutton(root,variable=sex,value=0,text='Woman')
radioWoman.place(x=130, y=70, width=70, height=20)
2.组合框
①声明以及初始化
#添加年龄组合框
studentAge=[]
for i in range(6,23):
studentAge.append(i)
labelAge=tkinter.Label(root,text="Age:",justify=tkinter.RIGHT,width=50)
labelAge.place(x=250, y=40, width=50, height=20)
comboAge=tkinter.ttk.Combobox(root,width=80,value=tuple(studentAge))
comboAge.place(x=310, y=40, width=50, height=20)
3.复选框
①声明以及初始化
#与是否班长关联的变量,默认当前学生不是班长
monitor = tkinter.IntVar()
monitor.set(0)
#复选框,选中时变量值为1,#未选中时变量值为0
checkMonitor = tkinter.Checkbutton(root,text='Is Monitor?', variable=monitor,onvalue=1, offvalue=0)
checkMonitor.place(x=20, y=100, width=100, height=20)
4.列表框
①声明以及初始化
listboxStudents