python开发_tkinter_获取单选菜单值
在之前的blog中有提到python的tkinter中的菜单操作
python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐
python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐(二)
python开发_tkinter_菜单选项中英文切换_菜单选项不可用操作_博主推荐
下面是tkinter的获取单选菜单值的操作
运行效果:
当点击'print party and flavor'按钮的时候,获取单选菜单的值

==========================================================
代码部分:
==========================================================
from tkinter import * # The way to think about this is that each radio button menu
# controls a different variable -- clicking on one of the
# mutually exclusive choices in a radiobutton assigns some value
# to an application variable you provide. When you define a
# radiobutton menu choice, you have the option of specifying the
# name of a varaible and value to assign to that variable when
# that choice is selected. This clever mechanism relieves you,
# the programmer, from having to write a dumb callback that
# probably wouldn't have done anything more than an assignment
# anyway. The Tkinter options for this follow their Tk
# counterparts:
# {"variable" : my_flavor_variable, "value" : "strawberry"}
# where my_flavor_variable is an instance of one of the
# subclasses of Variable, provided in Tkinter.py (there is
# StringVar(), IntVar(), DoubleVar() and BooleanVar() to choose
# from) __author__ = {'name' : 'Hongten',
'mail' : 'hongtenzone@foxmail.com',
'blog' : 'http://www.cnblogs.com/',
'QQ': '',
'created' : '2013-09-11'} def makePoliticalParties(var):
# make menu button
Radiobutton_button = Menubutton(mBar, text='Political Party',
underline=0)
Radiobutton_button.pack(side=LEFT, padx='2m') # the primary pulldown
Radiobutton_button.menu = Menu(Radiobutton_button) Radiobutton_button.menu.add_radiobutton(label='Republican',
variable=var, value=1) Radiobutton_button.menu.add('radiobutton', {'label': 'Democrat',
'variable' : var,
'value' : 2}) Radiobutton_button.menu.add('radiobutton', {'label': 'Libertarian',
'variable' : var,
'value' : 3}) var.set(2) # set up a pointer from the file menubutton back to the file menu
Radiobutton_button['menu'] = Radiobutton_button.menu return Radiobutton_button def makeFlavors(var):
# make menu button
Radiobutton_button = Menubutton(mBar, text='Flavors',
underline=0)
Radiobutton_button.pack(side=LEFT, padx='2m') # the primary pulldown
Radiobutton_button.menu = Menu(Radiobutton_button) Radiobutton_button.menu.add_radiobutton(label='Strawberry',
variable=var, value='Strawberry') Radiobutton_button.menu.add_radiobutton(label='Chocolate',
variable=var, value='Chocolate') Radiobutton_button.menu.add_radiobutton(label='Rocky Road',
variable=var, value='Rocky Road') # choose a default
var.set("Chocolate") # set up a pointer from the file menubutton back to the file menu
Radiobutton_button['menu'] = Radiobutton_button.menu return Radiobutton_button def printStuff():
print("party is", party.get())
print("flavor is", flavor.get())
print() #################################################
#### Main starts here ...
root = Tk() # make a menu bar
mBar = Frame(root, relief=RAISED, borderwidth=2)
mBar.pack(fill=X) # make two application variables,
# one to control each radio button set
party = IntVar()
flavor = StringVar() Radiobutton_button = makePoliticalParties(party)
Radiobutton_button2 = makeFlavors(flavor) # finally, install the buttons in the menu bar.
# This allows for scanning from one menubutton to the next.
mBar.tk_menuBar(Radiobutton_button, Radiobutton_button2) b = Button(root, text="print party and flavor", foreground="red",
command=printStuff)
b.pack(side=TOP) root.title('menu demo')
root.iconname('menu demo') root.mainloop()
参考资料:
http://www.oschina.net/code/explore/Python-3.1.3/Demo/tkinter/matt/two-radio-groups.py
python开发_tkinter_获取单选菜单值的更多相关文章
- python开发_tkinter_获取文本框内容_给文本框添加键盘输入事件
在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...
- python开发_tkinter_单选菜单_不可用菜单操作
在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...
- python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐(二)
在上一篇blog:python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 中介绍了python中的tkinter的一些东西,你可能对tkinter有一定的了解了.这篇b ...
- python开发_tkinter_小球完全弹性碰撞游戏
python开发_tkinter_小球完全弹性碰撞游戏 完成这个小球的完全弹性碰撞游戏灵感来自于: 下面是我花了一周下班时间所编写的一个小球完全弹性碰撞游戏: 游戏初始化状态: 最下面的游标和修改 ...
- python开发_tkinter_多级子菜单
在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...
- python开发_tkinter_复选菜单
在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...
- python开发_tkinter_菜单选项中英文切换_菜单选项不可用操作_博主推荐
我使用的python版本为:3.3.2 如果你对python中tkinter模块的菜单操作不是很了解,你可以看看: python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推 ...
- python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐
在了解python中的tkinter模块的时候,你需要了解一些tkinter的相关知识 下面是python的API文档中的一个简单例子: import tkinter as tk class Appl ...
- python开发_tkinter_小球完全弹性碰撞游戏_源码下载
完成这个小球的完全弹性碰撞游戏灵感来自于: 下面是我花了一周下班时间所编写的一个小球完全弹性碰撞游戏: 游戏初始化状态: 最下面的游标和修改小球的移动速度 ====================== ...
随机推荐
- MyBatis 总结记录
1.1MyBatis简介 MyBatis 是一个可以自定义SQL.存储过程和高级映射的持久层框架.MyBatis 摒除了大部分的JDBC代码.手工设置参数和结果集重获.MyBatis 只使用简单的XM ...
- 【工具记录】Linux口令破解
1.基础知识 /etc/passwd:记录着用户的基本属性,所有用户可读 字段含义如下: 用户名:口令:用户标识号:组标识号:注释性描述:主目录:登录Shell eg: root:x:0:0:root ...
- shell脚本编程之“最简单的死循环”【转】
转自:http://blog.chinaunix.net/uid-23046336-id-3475462.html 在linux下编程的程序猿都知道shell脚本,就算你不怎么熟悉,也应该听过的吧!那 ...
- C# WebClient进行FTP服务上传文件和下载文件
定义WebClient使用的操作类: 操作类名称WebUpDown WebClient上传文件至Ftp服务: //// <summary> /// WebClient上传文件至Ftp服务 ...
- python3中内建函数map()与reduce()的使用方法
map()的使用 map()的使用方法形如map(f(x),Itera).对,它有两个参数,第一个参数为某个函数,第二个为可迭代对象.如果不懂什么是函数,不懂什么是可迭代对象没关系,记住下面的例 ...
- iOS开发之删除Provisioning Profiles方法
1.在finder下打开go -> go to folder输入: ~/Library/MobileDevice/Provisioning Profiles 2.查看上面的列表,按照时间顺序删除 ...
- 01 Getting Started 开始
Getting Started 开始 Install the Go tools Test your installation Uninstalling Go Getting help Downlo ...
- android设备休眠
从上面的连接里面找到了一些资料: 如果一开始就对Android手机的硬件架构有一定的了解,设计出的应用程序通常不会成为待机电池杀手,而要设计出正确的通信机制与通信协议也并不困难.但如果不去了解而盲目设 ...
- 浅谈js变量作用域
变量的作用域也是前端面试题常考的一个问题,掌握下面几个规律可以帮你更好的理解js的作用域. 1.作用域优先级遵循就近原则,函数内部的作用域优先级大于外部 var a=456; var b=111; f ...
- 洛谷P2016战略游戏
传送门啦 战略游戏这个题和保安站岗很像,这个题更简单,这个题求的是士兵人数,而保安站岗需要求最优价值. 定义状态$ f[u][0/1] $ 表示 $ u $ 这个节点不放/放士兵 根据题意,如果当前节 ...