python开发_tkinter_菜单的不同选项
时间:2022-06-10
本文章向大家介绍python开发_tkinter_菜单的不同选项,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
python的tkinter模块中,菜单也可以由你自定义你的风格
下面是我做的demo
运行效果:
======================================
代码部分:
======================================
1 from tkinter import *
2
3 '''
4 菜单选项的不同形式
5 '''
6 #global var
7 number = 0
8 # some miscellaneous callbacks
9 def new_file():
10 global number
11 number += 1
12 tk = Tk()
13 tk.geometry('300x300')
14 tk.title('Demo %s'%number)
15
16 def open_file():
17 print("opening OLD file")
18
19 def print_something():
20 print("picked a menu item")
21
22 def makeCommandMenu():
23 # make menu button
24 Command_button = Menubutton(mBar, text='Simple Button Commands',
25 underline=0)
26 Command_button.pack(side=LEFT, padx="2m")
27
28 # make the pulldown part of the File menu. The parameter passed is the master.
29 # we attach it to the button as a python attribute called "menu" by convention.
30 # hopefully this isn't too confusing...
31 Command_button.menu = Menu(Command_button)
32
33 # just to be cute, let's disable the undo option:
34 Command_button.menu.add_command(label="Undo")
35 # undo is the 0th entry...
36 Command_button.menu.entryconfig(0, state=DISABLED)
37
38 Command_button.menu.add_command(label='New...', underline=0,
39 command=new_file)
40 Command_button.menu.add_command(label='Open...', underline=0,
41 command=open_file)
42 Command_button.menu.add_command(label='Different Font', underline=0,
43 font='-*-helvetica-*-r-*-*-*-180-*-*-*-*-*-*',
44 command=print_something)
45
46 # we can make bitmaps be menu entries too. File format is X11 bitmap.
47 # if you use XV, save it under X11 bitmap format. duh-uh.,..
48 Command_button.menu.add_command(
49 bitmap="info")
50 #bitmap='@/home/mjc4y/dilbert/project.status.is.doomed.last.panel.bm')
51
52 # this is just a line
53 Command_button.menu.add('separator')
54
55 # change the color
56 Command_button.menu.add_command(label='Quit', underline=0,
57 background='red',
58 activebackground='green',
59 command=Command_button.quit)
60
61 # set up a pointer from the file menubutton back to the file menu
62 Command_button['menu'] = Command_button.menu
63
64 return Command_button
65
66 #################################################
67 #### Main starts here ...
68 root = Tk()
69 root.geometry('300x300')
70
71
72 # make a menu bar
73 mBar = Frame(root, relief=RAISED, borderwidth=2)
74 mBar.pack(fill=X)
75
76 Command_button = makeCommandMenu()
77
78
79 # finally, install the buttons in the menu bar.
80 # This allows for scanning from one menubutton to the next.
81 mBar.tk_menuBar(Command_button)
82
83
84 root.title('menu demo')
85 root.iconname('menu demo')
86
87 root.mainloop()
E | hongtenzone@foxmail.com B | http://www.cnblogs.com/hongten
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Redis 怎么防止数据丢失?面试必问!
- 使用vs2015编写c语言的方法
- 哪些场景会产生OOM?怎么解决?
- 预处理命令
- IntelliJ IDEA 调试 Java 8 Stream,实在太香了!
- 仅需四步,写一个 Spring Boot Starter
- 一个简单案例,带你看懂GC日志!
- C#中ref和out的区别使用
- 图解 MySQL 索引,写得实在太好了!
- 10、图像的几何变换——平移、镜像、缩放、旋转、仿射变换 OpenCV2:图像的几何变换,平移、镜像、缩放、旋转(1)OpenCV2:图像的几何变换,平移、镜像、缩放、旋转(2)数字图像
- String、StringBuiler、StringBuffer,谁性能最高?
- 图像的几何变换——平移、镜像、缩放、旋转、仿射变换 OpenCV2:图像的几何变换,平移、镜像、缩放、旋转(1)OpenCV2:图像的几何变换,平移、镜像、缩放、旋转(2)数字图像处理笔
- 详说C#中的结构struct
- c#结构体总结
- 跨域问题(CORS / Access-Control-Allow-Origin)