Radiobutton
界面:
代码:
# 单选组件Radiobutton
import tkinter as tk
window = tk.Tk()
window.geometry('300x300+200+200')
label1 = tk.Label(window, text='请为您最喜欢的体育投票')
label1.grid(row=1, column=1, columnspan=2)
window.mainloop()
Spinbox
界面:
代码:
# 滚动组件
import tkinter as tk
win = tk.Tk()
win.geometry('300x200+200+200')
win.title('Spinbox_example')
# 文本说明文字
label1 = tk.Label(text='请选择评语和成绩', font=('隶属', 15))
label1.pack(expand=1, fill='x')
label2 = tk.Label(font=('宋体', 18))
label2.pack()
# 设置科目和分数的两个滚动组件
subject = tk.StringVar()
score = tk.IntVar()
spin1 = tk.Spinbox(textvariable=subject,
value=('语文', '数学', '英语'),
wrap=True)
spin1.pack()
spin2 = tk.Spinbox(textvariable=score,
from_=60,
to=100,
increment=5,
wrap=True)
spin2.pack()
def change(): # 将滚动组件内容显示到label2上
label2.config(text=subject.get()+str(score.get()))
# 设置确定键
bt = tk.Button(text='确定', command=change)
bt.pack()
win.mainloop()