python开发_tkinter_复选菜单
在之前的blog中有提到python的tkinter中的菜单操作
python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐
python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐(二)
python开发_tkinter_菜单选项中英文切换_菜单选项不可用操作_博主推荐
下面是tkinter中复选菜单的操作
运行效果:
1.初始化的时候,最后一个子菜单被选中。

2.选择子菜单项,所触发的事件...

==============================================================
代码部分:
==============================================================
 from tkinter import *
 __author__ = {'name' : 'Hongten',
               'mail' : 'hongtenzone@foxmail.com',
               'blog' : 'http://www.cnblogs.com/',
               'QQ': '',
               'created' : '2013-09-10'}
 #状态标志
 pepperonis = False
 anchovies = 0
 def print_pepperonis():
     global pepperonis
     pepperonis = not pepperonis
     print('pepperonis?', pepperonis)
 def print_anchovies():
     '''从这里我们可以判断出'Anchovy'子菜单是否处于选择状态'''
     global anchovies
     anchovies = not anchovies
     print("anchovies?", anchovies)
 def makeCheckbuttonMenu():
     # make menu button
     Checkbutton_button = Menubutton(mBar, text='Checkbutton Menus',
                                     underline=0)
     Checkbutton_button.pack(side=LEFT, padx='2m')
     # the primary pulldown
     Checkbutton_button.menu = Menu(Checkbutton_button)
     # and all the check buttons. Note that the "variable" "onvalue" and "offvalue" options
     # are not supported correctly at present. You have to do all your application
     # work through the calback.
     Checkbutton_button.menu.add_checkbutton(label='Pepperoni', command=print_pepperonis)
     Checkbutton_button.menu.add_checkbutton(label='Sausage')
     Checkbutton_button.menu.add_checkbutton(label='Extra Cheese')
     # so here's a callback
     Checkbutton_button.menu.add_checkbutton(label='Anchovy',
                                             command=print_anchovies)
     #初始化时,被选中状态
     #
     # and start with anchovies selected to be on. Do this by
     # calling invoke on this menu option. To refer to the "anchovy" menu
     # entry we need to know it's index. To do this, we use the index method
     # which takes arguments of several forms:
     #
     # argument        what it does
     # -----------------------------------
     # a number        -- this is useless.
     # "last"          -- last option in the menu
     # "none"          -- used with the activate command. see the man page on menus
     # "active"        -- the currently active menu option. A menu option is made active
     #                         with the 'activate' method
     # "@number"       -- where 'number' is an integer and is treated like a y coordinate in pixels
     # string pattern  -- this is the option used below, and attempts to match "labels" using the
     #                    rules of Tcl_StringMatch
     Checkbutton_button.menu.invoke(Checkbutton_button.menu.index('Anchovy'))
     # set up a pointer from the file menubutton back to the file menu
     Checkbutton_button['menu'] = Checkbutton_button.menu
     return Checkbutton_button
 #################################################
 #### Main starts here ...
 root = Tk()
 root.geometry('250x200')
 root.title('menu demo')
 root.iconname('menu demo')
 # make a menu bar
 mBar = Frame(root, relief=RAISED, borderwidth=2)
 mBar.pack(fill=X)
 Checkbutton_button = makeCheckbuttonMenu()
 mBar.tk_menuBar(Checkbutton_button)
 root.mainloop()
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_获取文本框内容_给文本框添加键盘输入事件
		在之前的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_博主推荐(二)
		在上一篇blog:python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 中介绍了python中的tkinter的一些东西,你可能对tkinter有一定的了解了.这篇b ... 
- python开发_tkinter_小球完全弹性碰撞游戏
		python开发_tkinter_小球完全弹性碰撞游戏 完成这个小球的完全弹性碰撞游戏灵感来自于: 下面是我花了一周下班时间所编写的一个小球完全弹性碰撞游戏: 游戏初始化状态: 最下面的游标和修改 ... 
- 安卓开发_复选按钮控件(CheckBox)的简单使用
		复选按钮 即可以选择若干个选项,与单选按钮不同的是,复选按钮的图标是方块,单选按钮是圆圈 复选按钮用CheckBox表示,CheckBox是Button的子类,支持使用Button的所有属性 一.由于 ... 
- FineReport——JS二次开发(复选框全选)
		在进行查询结果选择的时候,我们经常会用到复选框控件,对于如何实现复选框全选,基本思路: 在复选框中的初始化事件中把控件加入到一个全局数组里,然后在全选复选框里对数组里的控件进行遍历赋值. 首先,定义两 ... 
随机推荐
- linux中core dump开启使用教程【转】
			转自:http://www.111cn.net/sys/linux/67291.htm 一.什么是coredump 我们经常听到大家说到程序core掉了,需要定位解决,这里说的大部分是指对应程序由于各 ... 
- PHP的数据库连接mysqli遍历示例
			$mysqli = mysqli_init(); $mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 2);//设置超时时间,以秒为单位的连接超时时间 $m ... 
- asp.net mvc 本地化 默认的错误提示
			System.ComponentModel.DataAnnotations 给我们提供了一些特性来直接对model的属性进行验证和约束, 同时也提供了 ErrorMessageResourceName ... 
- 表格中border-collapse属性
			页面制作中最头痛的,表格的边框算是其一了.一不小心就会出现双重线 border-collapse属性 很好的解决了纠结了很久的问题 .table{border: 1px solid #ccc;bord ... 
- java基础17 模板模式
			1.模版模式 解决某类事物的步骤有些是固定的,有些会发生改变的,那么这个时候我们可以为这一类事物提供一个模版代码,从而提高效率. 2.模版模式的步骤 1.先写出解决该类事物的其中一种解决方案; ... 
- R vs Python:载入包 import & library
			数据科学:R & Python 工作 & Kaggle机器学习比赛 可重复函数式编程 一.Python模块的载入 包 Package 模块 module import pandas a ... 
- Jenkins在Linux环境安装
			Jenkins介绍 Jenkins是基于Java开发的一种持续集成工具,用于监控持续重复的工作,功能包括: 1.持续的软件版本发布/测试项目. 2.监控外部调用执行的工作. 安装环境 操作系统:lin ... 
- Redux-DevTools 安装
			以下以Chrome为准. 首先,从Chrome Web Store(需要***支持)下载chrome 插件 Redux DevTools. 使用方式有两种: 一种只需在代码createStore中添加 ... 
- 计算Python代码运行时间长度方法
			在代码中有时要计算某部分代码运行时间,便于分析. import time start = time.clock() run_function() end = time.clock() print st ... 
- Loadrunner乱码问题
			在LoadRunner中录制脚本时,出现乱码的问题解决 我在录制一个Web的脚本时,出现中文乱码. 原因为Web中采用的是UTF-8编码,而录制脚本的选项默认没有把支持UTF8选中. 方法:1. To ... 
