在之前的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_复选菜单的更多相关文章

  1. python开发_tkinter_多级子菜单

    在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...

  2. python开发_tkinter_单选菜单_不可用菜单操作

    在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...

  3. python开发_tkinter_获取文本框内容_给文本框添加键盘输入事件

    在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...

  4. python开发_tkinter_获取单选菜单值

    在之前的blog中有提到python的tkinter中的菜单操作 python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 python开发_tkinter_窗口控件_自 ...

  5. python开发_tkinter_菜单选项中英文切换_菜单选项不可用操作_博主推荐

    我使用的python版本为:3.3.2 如果你对python中tkinter模块的菜单操作不是很了解,你可以看看: python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推 ...

  6. python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐(二)

    在上一篇blog:python开发_tkinter_窗口控件_自己制作的Python IDEL_博主推荐 中介绍了python中的tkinter的一些东西,你可能对tkinter有一定的了解了.这篇b ...

  7. python开发_tkinter_小球完全弹性碰撞游戏

    python开发_tkinter_小球完全弹性碰撞游戏   完成这个小球的完全弹性碰撞游戏灵感来自于: 下面是我花了一周下班时间所编写的一个小球完全弹性碰撞游戏: 游戏初始化状态: 最下面的游标和修改 ...

  8. 安卓开发_复选按钮控件(CheckBox)的简单使用

    复选按钮 即可以选择若干个选项,与单选按钮不同的是,复选按钮的图标是方块,单选按钮是圆圈 复选按钮用CheckBox表示,CheckBox是Button的子类,支持使用Button的所有属性 一.由于 ...

  9. FineReport——JS二次开发(复选框全选)

    在进行查询结果选择的时候,我们经常会用到复选框控件,对于如何实现复选框全选,基本思路: 在复选框中的初始化事件中把控件加入到一个全局数组里,然后在全选复选框里对数组里的控件进行遍历赋值. 首先,定义两 ...

随机推荐

  1. Shell中三种引号的用法及区别

    Linux Shell中有三种引号,分别为双引号(" ").单引号(' ')以及反引号(` `). 其中双引号对字符串中出现的$.''.`和\进行替换:单引号不进行替换,将字符串中 ...

  2. 聊天室(下篇)GatewayWorker 与 Laravel 的整合

    思路 上一篇大概梳理了一下 GatewayWorker 的基础知识.这篇就来准备整合 GatewayWorker 到 Laravel. GatewayWorker 是基于 Socket 监听的服务器框 ...

  3. python 结构化数据解析

    # -*- coding: utf-8 -*- # @Time : 2018/8/31 14:32 # @Author : cxa # @File : glomtest.py # @Software: ...

  4. Django-自动HTML转义

    一.自动HTML转义 从模板生成HTML时,总会有变量包含影响最终HTML的字符风险,例如,考虑这个模板的片段: Hello, {{ name }} 起初,这是一种显示用户名的无害方式,但考虑用户输入 ...

  5. Java HashCode详解

    一.为什么要有Hash算法 Java中的集合有两类,一类是List,一类是Set.List内的元素是有序的,元素可以重复.Set元素无序,但元素不可重复.要想保证元素不重复,两个元素是否重复应该依据什 ...

  6. 删除数据库所有存储过程的SQL语句

    --/第1步**********删除所有表的外键约束*************************/ DECLARE c1 cursor for select 'alter table ['+ o ...

  7. Java学习(异常类)

    一.什么是异常: 异常就是在运行时产生的问题.通常用Exception描述. 在java中,把异常封装成了一个类,当出现问题时,就会创建异常类对象并抛出异常相关的信息(如详细信息,名称以及异常所处的位 ...

  8. 【58沈剑架构系列】RPC-client异步收发核心细节?

    第一章聊了[“为什么要进行服务化,服务化究竟解决什么问题”] 第二章聊了[“微服务的服务粒度选型”] 第三章聊了[“为什么说要搞定微服务架构,先搞定RPC框架?”] 上一章聊了[“微服务架构之RPC- ...

  9. D - Round Subset codeforces837d

    D - Round Subset 思路:背包: 代码: #include <cstdio> #include <cstring> #include <iostream&g ...

  10. .size和.empty

    坑爹的list容器size方法--为了splice居然把复杂度设计为O(N)? 能用empty的时候,不要用size empty可以保证常量复杂度,但list的size不保证 链表长度必须要遍历全部的 ...