栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Python 2.7 Tkinter-确定已选择哪个单选按钮

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python 2.7 Tkinter-确定已选择哪个单选按钮

关键是要确保两个单选按钮共享相同的变量。然后,要知道选择了哪个变量,您只需要获取变量的值即可。

这是一个例子:

import tkinter# function that is called when you select a certain radio buttondef selected():    print(var.get())root = tkinter.Tk()var = tkinter.StringVar() #used to get the 'value' property of a tkinter.Radiobutton# Note that I added a command to each radio button and a different 'value'# When you press a radio button, its corresponding 'command' is called.# In this case, I am linking both radio buttons to the same command: 'selected'rb1 = tkinter.Radiobutton(text='Radio Button 1', variable=var,     value="Radio 1", command=selected)rb1.pack()rb2 = tkinter.Radiobutton(text='Radio Button 2', variable=var,     value="Radio 2", command=selected)rb2.pack()root.mainloop()


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/623778.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号