import tkinter as tk
window = tk.Tk()
window.title(‘kobe’)
window.geometry(‘400x300’)
#将选项放到Label框架里,三个球星
group = tk.LabelFrame(window,text=‘最强大的球星’)
group.pack()
language = [(‘詹姆斯’,1),(‘哈登’,2),(‘科比’,3)]
var = tk.IntVar()
for lan,num in language:
b = tk.Radiobutton(group,text=lan,variable=var,value=num,indicatoron=‘false’)
b.pack(fill=‘y’)
#1,2,3,的出现
tk.Radiobutton(window,text=‘1’,variable=var,value=4).pack()
tk.Radiobutton(window,text=‘2’,variable=var,value=5).pack()
tk.Radiobutton(window,text=‘3’,variable=var,value=6).pack()
#三个语言的实现
v = []
group = [‘java’,‘python’,‘c++’]
for yuyan in group:
v.append(tk.IntVar())
b = tk.Checkbutton(window,text=yuyan,variable=v[-1])
b.pack()
l = tk.Label(window,text=‘ss’)
l.pack(side=‘bottom’)
window.mainloop()
小记:indicatoron:选择为false时选择为边框,默认为圆点
tk.LabelFrame:选项放置到框架里
Radiobutton为单选,相同的variable,不同的value值
Checkbutton为多项选择