tkinter学习_radiobutton

#encoding=utf-8
import tkinter as tk
window = tk.Tk()
window.title("测试单选框")
window.geometry("400x200")

var = tk.StringVar()

label_1 = tk.Label(window,bg="yellow",textvar=var,width=10,height=1,text="label_1")
label_1.pack()

def print_selection():
    #label的config函数可以改变label对象里定义的参数的值
    label_1.config(text= "你选择了选项: " + var.get())
    label_1.config(bg="green")
    label_1.config(width=12)
#定义单选按钮,var=var,value="A" 指把value的值赋值给var
radiobutton_1 = tk.Radiobutton(window,text="选项A",var=var,value="A",command=print_selection)
radiobutton_1.pack()

radiobutton_2 = tk.Radiobutton(window,text="选项B",var=var,value="B",command=print_selection)
radiobutton_2.pack()

radiobutton_3 = tk.Radiobutton(window,text="选项C",var=var,value="C",command=print_selection)
radiobutton_3.pack()

window.mainloop()

网站题目:tkinter学习_radiobutton
浏览地址:http://lszwz.com/article/gjddps.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款