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二次开发(复选框全选)
		
在进行查询结果选择的时候,我们经常会用到复选框控件,对于如何实现复选框全选,基本思路: 在复选框中的初始化事件中把控件加入到一个全局数组里,然后在全选复选框里对数组里的控件进行遍历赋值. 首先,定义两 ...
 
随机推荐
- vue总结 08状态管理vuex
			
状态管理 类 Flux 状态管理的官方实现 由于状态零散地分布在许多组件和组件之间的交互中,大型应用复杂度也经常逐渐增长.为了解决这个问题,Vue 提供 vuex:我们有受到 Elm 启发的状态管 ...
 - IntelliJ IDEA 去除IDE自动的参数名 提示功能
 - linux内核之accept实现
			
用户态对accept的标准用法: if ((client_fd = accept(sockfd, (struct sockaddr *)&remote_addr, &sin_size) ...
 - JavaScript工程师都应懂的33个概念
			
最近福利发的有点多啊,各种硬干货,小伙伴们是不是觉得很爽啊.Github真的蕴含着各种各样的宝藏,难怪各个大厂也都纷纷贡献自己的代码到Github上. 所以各种干货还是会源源不断的po给大家,觉得有帮 ...
 - CCF CSP 201509-4 高速公路
			
CCF计算机职业资格认证考试题解系列文章为meelo原创,请务必以链接形式注明本文地址 CCF CSP 201509-4 高速公路 问题描述 某国有n个城市,为了使得城市间的交通更便利,该国国王打算在 ...
 - Java学习(Map接口)
			
一.概述: 我们通过查看Map接口描述,发现Map接口下的集合与Collection接口下的集合,它们存储数据的形式不同,如下图. 1. Collection中的集合,元素是孤立存在的(理解为单身), ...
 - python开发学习-day16(Django框架初识)
			
s12-20160507-day16 *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: ...
 - bzoj 1237 [SCOI2008]配对  贪心+dp
			
思路:dp[ i ] 表示 排序后前 i 个元素匹配的最小值, 我们可以发现每个点和它匹配的点的距离不会超过2,这样就能转移啦. #include<bits/stdc++.h> #defi ...
 - hive将数据导致本地磁盘
			
hive -e "select * from wyp" >> local/wyp.txt 其中我更喜欢弄好临时表,然后交互式查询时让相关人员自己去按逻辑处理数据,最 ...
 - 006 ajax验证用户名
			
1.大纲 2.index.jsp <%@ page language="java" contentType="text/html; charset=UTF-8&qu ...