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_小球完全弹性碰撞游戏_源码下载
完成这个小球的完全弹性碰撞游戏灵感来自于: 下面是我花了一周下班时间所编写的一个小球完全弹性碰撞游戏: 游戏初始化状态: 最下面的游标和修改小球的移动速度 ====================== ...
随机推荐
- Dom解析XML文件具体用法
public class Dom4j { public static void main(String[] args) throws Exception { List<Student> l ...
- F5后端nginx+tomcat应用如何获得用户的真实ip【转】
根据业务需要要求记录每个通过wap或者客户端访问我们服务器的用户真实ip但是由于业务前端部署了两个3900系列的F5设备导致程序一直获得F5设备自身的ip,所以笔者考虑可能是因为F5导致无法获得用户的 ...
- iBt(001-004)原文与试译
Unit 001 Basic building materials include: timber, mud, stone, marble, brick, tile, steel, and cemen ...
- python configparser配置文件解析器
一.Configparser 此模块提供实现基本配置语言的ConfigParser类,该语言提供类似于Microsoft Windows INI文件中的结构.我们经常会在一些软件安装目录下看到.ini ...
- docker centos:last 开启sshd 遇到的证书问题
启动sshd: # /usr/sbin/sshd 一.问题描述 这时报以下错误: [root@ xxx/]# /usr/sbin/sshd Could not load host key: /etc/ ...
- wiki confluence安装
注意:安装前请先确认内存 至少2G 1.上传 atlassian-confluence-5.9.3-x64.bin 文件,修改权限 chmod 777 atlassian-confluence-5.9 ...
- 泛型 for to/in 遍历 PK 效率;TEnumerator、TEnumerable
再使用泛型的时候,经常需要用到遍历功能: 只要继承了 TEnumerator 或 TEnumerable 这两个抽象类的 都具有遍历功能. 当然没有继承这两个抽象类的 也具有使用 for in 来遍历 ...
- 网络编程--Socket与ServerSocket
1.服务器端代码 package net; import java.io.PrintStream; import java.net.ServerSocket; import java.net.Sock ...
- Pyhton核心编程-Chap2习题-DIY
在学Python,在看<Python核心编程>的pdf,做了Chap2的题目,答案为DIY # Filename: 2-11.py # Author: ChrisZZ mylist = [ ...
- USACO 6.2 Calf Flac
Calf Flac It is said that if you give an infinite number of cows an infinite number of heavy-duty la ...