5.radiobutton选择按钮
定义一个label作为提示框,
注意l.config()可以更新label中的text内容
tk.radiobutton()中传入的参数
import tkinter as tk
window = tk.Tk()
window.title("my window")
window.geometry('200x200')
var = tk.StringVar() # 定义一个变量
l = tk.Label(window, bg='yellow', width=20, text='empty')
l.pack()
def print_selection():
l.config(text='you have selected ' + var.get())
# 在window上显示为Option A,当选中时,将variable的var赋值为value:A
r1 = tk.Radiobutton(window, text='Option A', variable=var, value='A', command=print_selection)
r1.pack()
r2 = tk.Radiobutton(window, text='Option B', variable=var, value='B', command=print_selection)
r2.pack()
r3 = tk.Radiobutton(window, text='Option C', variable=var, value='C', command