- Tkinter GUI Application Development Blueprints(Second Edition)
- Bhaskar Chaudhary
- 233字
- 2021-06-24 18:35:08
Adding a menu and menu items
Menus offer a very compact way of presenting a large number of choices to the user without cluttering the interface. Tkinter offers the following two widgets to handle menus:
- Menu widget: This appears at the top of applications, which is always visible to end users
- Menu items: These show up when a user clicks on a menu
We will use the following code to add Toplevel menu buttons:
my_menu = Menu(parent, **options)
For example, to add a File menu, we will use the following code:
# Adding Menubar in the widget
menu_bar = Menu(root)
file_menu = Menu(menu_bar, tearoff=0)
# all file menu-items will be added here next
menu_bar.add_cascade(label='File', menu=file_menu)
root.config(menu=menu_bar)
The following screenshot is the result of the preceding code (2.01.py):

Similarly, we will add the Edit, View, and About menus (2.01.py).
We will also define a constant as follows:
PROGRAM_NAME = " Footprint Editor "
Then, we'll set the root window tile, as follows:
root.title(PROGRAM_NAME)
Most Linux platforms support tear-off menus. When tearoff is set to 1 (enabled), the menu appears with a dotted line above the menu options. Clicking on the dotted line enables the user to literally tear off or separate the menu from the top. However, as this is not a cross-platform feature, we have decided to disable tear-off, marking it as tearoff = 0.
- WildFly:New Features
- HTML5移動Web開發技術
- TypeScript入門與實戰
- Hands-On Machine Learning with scikit:learn and Scientific Python Toolkits
- 手把手教你學C語言
- 大數據分析與應用實戰:統計機器學習之數據導向編程
- Building Android UIs with Custom Views
- IBM Cognos Business Intelligence 10.1 Dashboarding cookbook
- Building Microservices with .NET Core
- Java Web從入門到精通(第3版)
- Java 11 and 12:New Features
- Software Architecture with Python
- Processing開發實戰
- Spring Boot學習指南:構建云原生Java和Kotlin應用程序
- HTML5/CSS3/JavaScript技術大全