python的tkinter模块中,菜单也可以由你自定义你的风格

下面是我做的demo

运行效果:

======================================

代码部分:

======================================

 from tkinter import *

 '''
菜单选项的不同形式
'''
#global var
number = 0
# some miscellaneous callbacks
def new_file():
global number
number += 1
tk = Tk()
tk.geometry('300x300')
tk.title('Demo %s'%number) def open_file():
print("opening OLD file") def print_something():
print("picked a menu item") def makeCommandMenu():
# make menu button
Command_button = Menubutton(mBar, text='Simple Button Commands',
underline=0)
Command_button.pack(side=LEFT, padx="2m") # make the pulldown part of the File menu. The parameter passed is the master.
# we attach it to the button as a python attribute called "menu" by convention.
# hopefully this isn't too confusing...
Command_button.menu = Menu(Command_button) # just to be cute, let's disable the undo option:
Command_button.menu.add_command(label="Undo")
# undo is the 0th entry...
Command_button.menu.entryconfig(0, state=DISABLED) Command_button.menu.add_command(label='New...', underline=0,
command=new_file)
Command_button.menu.add_command(label='Open...', underline=0,
command=open_file)
Command_button.menu.add_command(label='Different Font', underline=0,
font='-*-helvetica-*-r-*-*-*-180-*-*-*-*-*-*',
command=print_something) # we can make bitmaps be menu entries too. File format is X11 bitmap.
# if you use XV, save it under X11 bitmap format. duh-uh.,..
Command_button.menu.add_command(
bitmap="info")
#bitmap='@/home/mjc4y/dilbert/project.status.is.doomed.last.panel.bm') # this is just a line
Command_button.menu.add('separator') # change the color
Command_button.menu.add_command(label='Quit', underline=0,
background='red',
activebackground='green',
command=Command_button.quit) # set up a pointer from the file menubutton back to the file menu
Command_button['menu'] = Command_button.menu return Command_button #################################################
#### Main starts here ...
root = Tk()
root.geometry('300x300') # make a menu bar
mBar = Frame(root, relief=RAISED, borderwidth=2)
mBar.pack(fill=X) Command_button = makeCommandMenu() # finally, install the buttons in the menu bar.
# This allows for scanning from one menubutton to the next.
mBar.tk_menuBar(Command_button) root.title('menu demo')
root.iconname('menu demo') root.mainloop()

========================================================

More reading,and english is important.

I'm Hongten

大哥哥大姐姐,觉得有用打赏点哦!多多少少没关系,一分也是对我的支持和鼓励。谢谢。
Hongten博客排名在100名以内。粉丝过千。
Hongten出品,必是精品。

E | hongtenzone@foxmail.com  B | http://www.cnblogs.com/hongten

========================================================

python开发_tkinter_菜单的不同选项的更多相关文章

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

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

  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_获取文本框内容_给文本框添加键盘输入事件

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

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

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

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

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

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

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

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

    在了解python中的tkinter模块的时候,你需要了解一些tkinter的相关知识 下面是python的API文档中的一个简单例子: import tkinter as tk class Appl ...

随机推荐

  1. Explorer : 发布一个key-value存储系统,带有客户端和服务器端

    Explorer 一个key-value存储系统,带有客户端和服务器端.使用非常方便. 使用B+树作为存储引擎,客户端和服务器端使用TCP协议进行通信. 代码采用C++实现,底层将客户端和服务器通信封 ...

  2. The data protection operation was unsuccessful. This may have been caused by not having the user profile loaded for the current thread's user context,

    在iis7.0布署网站后运行的错误,大致意思是:数据保护操作是不成功的.这可能是由于没有为当前线程的用户加载用户配置文件的导致 解决办法: 先为自己的网站新建一个应用程序池,然后新建的应用程序池上右键 ...

  3. 数论-求n以内的质数

    一.埃拉托斯特尼筛法 名字很高大上,然而并没有什么卵用…… 思路: 在把<=√n的质数所有的<=n的倍数剔除,剩下的就都是质数了,很容易理解…… 复杂度O(nloglogn) #inclu ...

  4. Scrapy:创建爬虫程序的方式

    Windows 10家庭中文版,Python 3.6.4,Scrapy 1.5.0, 在Scrapy中,建立爬虫程序或项目的方式有两种(在孤读过Scrapy的大部分文档后): 1.继承官方Spider ...

  5. 使用Docker快速搭建sftp服务

    一.安装docker环境 参见 http://www.cnblogs.com/rslai/p/8403350.html 二.从Docker Hub查找sftp镜像 docker search sftp ...

  6. Linux基础 - crontab

    列出当前用户设置的定时任务 crontab -l 编辑定时任务 crontab -e 用法 m h dom mon dow * * * * * command 字段详解: *:any m: minut ...

  7. Linux学习笔记:输入输出重定向 >>命令

    Linux重定向是指修改原来默认的一些东西,对原来系统命令的默认执行方式进行改变.比如说我不想看到在显示器的输出,而是希望输出到某一文件中就可以通过Linux重定向来进行这项工作. 将stdout重定 ...

  8. 浅谈C#中的值类型和引用类型

    在C#中,值类型和引用类型是相当重要的两个概念,必须在设计类型的时候就决定类型实例的行为.如果在编写代码时不能理解引用类型和值类型的区别,那么将会给代码带来不必要的异常.很多人就是因为没有弄清楚这两个 ...

  9. 如何在k8s集群里快速运行一个镜像?

    在docker里,快速run一个镜像,很简单的. k8s的世界,与之类似. 但要注意一下,如果镜像本身没有提供command命令,这个容器由于前台输出完成,很快就退出了. 所以,遇到这种镜像,就最好自 ...

  10. Dubbo的特点

    1.介绍 DUBBO有良好的连通性.健壮性.伸缩性.升级性.结合dubbo可以相对于单体系统提升系统整体的扩展性 2. 连通性 注册中心负责服务地址的注册与查找,相当于目录服务,服务提供者和消费者只在 ...