Popup Menu in Tkinter
Tkinter is Python’s standard GUI (Graphical User Interface) package. It is one of the most commonly used packages for GUI applications which comes with the Python itself.
Note: For more information, refer to Python GUI – tkinter
Menus are an important part of any GUI. A common use of menus is to provide convenient access to various operations such as saving or opening a file, quitting a program, or manipulating data. Toplevel menus are displayed just under the title bar of the root or any other top-level windows.
menu = Menu(master, **options)
Note: For more information, refer to Python | Menu widget in Tkinter
Popup menus are context menus that appear on user interaction. This menu can be shown anywhere on the client window. below is the python code to create a popup menu using Tkinter library.
The popup menu in above code appears on right-click.
- Menu(root): creates the menu.
- add_command(label, command): adds the commands on the menu, the command argument calls the function hey() when that option is clicked.
- add_separator(): adds a separator.
- tk_popup(x, y): posts the menu at the position given as arguments
- grab_release(): releases the event grab
- bind(key, event): binds the mouse event.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course