- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Tkinter dropdown Menu with keyboard shortcuts
A Dropdown Menu is nothing but a list of vertically stacked menu items that can be visible at the top Menu Bar of an application. We can create a Menu bar in a Tkinter application by creating an object of Menu() in which all the Menu items are present.
There might be a case when we want to select the menu and perform some basic operations using Keyboard shortcuts. In order to bind the key to all the Menu, we use the bind_all(<Key>, callback) method.
Example
In this example, the application window contains a Menu of items. When we press the combination of <Ctrl + Q>, it will close the Main window.
#Import the required libraries from tkinter import * #Create an instance of Tkinter Frame win = Tk() #Set the geometry win.geometry("750x350") def exit(): win.destroy() #Create a Menu Bar menubar= Menu() filemenu= Menu(menubar, tearoff=False) menubar.add_cascade(label= "File",underline=0, menu= filemenu) filemenu.add_command(label="1.a", underline= 1) filemenu.add_command(label="2.b", underline= 1) filemenu.add_command(label="3.c", underline= 1) filemenu.add_command(label="Quit", underline= 1, command= exit, accelerator= "Ctrl+Q") win.config(menu= menubar) filemenu.bind_all("<Control-q>", exit) win.mainloop()
Output
Running the above code will display a window that contains a Label text and a Menu on the Menu Bar.
Now, click the menu item "Quit" or press <Ctrl+ Q> to close the main window.
- Related Articles
- Keyboard shortcuts with Tkinter in Python 3
- Creating a Dropdown Menu using Tkinter
- Create Dropdown menu with Bootstrap
- Top Keyboard Shortcuts For Mozilla Firefox
- Top Keyboard Shortcuts for Google Chrome
- How can I create a dropdown menu from a List in Tkinter?
- Top Keyboard Shortcuts For Mozilla Firefox Browser
- How to disable the keyboard shortcuts in Matplotlib?
- How to create a hoverable dropdown menu with CSS?
- Add header to label sections in dropdown menu with Bootstrap
- Right align a Bootstrap dropdown menu
- Making Menu options with Checkbutton in Tkinter?
- How to create a clickable dropdown menu with CSS and JavaScript?
- Add dropdown menu to buttons using Bootstrap
- Separate links in the dropdown menu with a thin horizontal border with Bootstrap
