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_小球完全弹性碰撞游戏_源码下载
完成这个小球的完全弹性碰撞游戏灵感来自于: 下面是我花了一周下班时间所编写的一个小球完全弹性碰撞游戏: 游戏初始化状态: 最下面的游标和修改小球的移动速度 ====================== ...
随机推荐
- Git 管理本地代码【转】
转自:http://www.cnblogs.com/JessonChan/archive/2011/03/16/1986570.html 以前用SVN,不过没有用出感情来:倒是用出不少怨恨:由于没有很 ...
- qt使用动态库(DLL)
本文主要讲解在QT开发环境中如何使用VC生成的DLL及QT自身生成的DLL.至于其它情况本文不作讨论. 连接库分为2种 (1)动态连接库,通常有.h .lib .dll三个文件,功能实现在dll中 ( ...
- CNN Architectures(AlexNet,VGG,GoogleNet,ResNet,DenseNet)
AlexNet (2012) The network had a very similar architecture as LeNet by Yann LeCun et al but was deep ...
- 【转】shell命令中>/dev/null 2>&1的实现原理
异步执行 exec("/alidata/server/php/bin/php /nas/wxdoctor/index.php App/Common/WordsPic/user_id/&quo ...
- HDU 3613 Best Reward(manacher求前、后缀回文串)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3613 题目大意: 题目大意就是将字符串s分成两部分子串,若子串是回文串则需计算价值,否则价值为0,求分 ...
- springMVC源码分析--HttpMessageConverter写write操作(三)
上一篇博客springMVC源码分析--HttpMessageConverter参数read操作中我们已经简单介绍了参数值转换的read操作,接下来我们介绍一下返回值的处理操作.同样返回值的操作操作也 ...
- ssh连接报错Write failed: Broken pipe Resource temporarily unavailable
问题描述 使用root连接服务器正常,切换普通用户连接报错 具体报错如下:Write failed: Broken pipe 或者:failed to execute /bin/bash: Resou ...
- WordPress引入css/js两种方法
WordPress引入css/js 是我们制作主题时首先面对的一个难点,任何一款主题都要加载自己的css,js,甚至很有可能还需要加载Jquery文件,网上方法特多,说法不一,我们今天借鉴wordpr ...
- 浏览器开启web通知。
https://www.cnblogs.com/xcsn/p/7767092.html
- 移动端css单位之 “vh” & “vw”
一.前言: 响应式web设计离不开百分比.但是,CSS百分比并不是所有的问题的最佳解决方案.CSS的宽度是相对于包含它的最近的父元素的宽度的.但是如果你就想用视口(viewpoint)的宽度或者高度, ...