Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use TKinter pop-up menu in python

Shulou Source: shulou.com Published: 2022-06-03 05:16:48 10月02日 Update

This article mainly introduces how to use the TKinter pop-up menu in python. It is very detailed and has a certain reference value. Friends who are interested must read it!

1. Pop-up menus are also called context menus, which establish menus and add various functions to the menus.

2. Right-click to monitor the mouse. If the right button is clicked, it will pop up according to the location.

3. Call the Menupop method.

4. Add_separator adds a delimiter.

Example

# Pop-up menu case import tkinter def makeLabel (): global baseFrame tkinter.Label (baseFrame, text= "PHP is the best programming language I use Python "). Pack () baseFrame = tkinter.Tk () menubar = tkinter.Menu (baseFrame) for x in ['spicy mushroom', 'steamed pot chicken', 'Braised Dongpo Pork Hock with Brown Sauce']: menubar.add_separator () menubar.add_command (label=x) menubar.add_command (label=" Chongqing hot pot ", command=makeLabel) # event handler must have at least one parameter And the first parameter represents the system event def pop (event): # pay attention to the difference between event.x and event.x_root # menubar.post (event.x, event.y) menubar.post (event.x_root, event.y_root) baseFrame.bind ("", pop) baseFrame.mainloop () above is all the content of the article "how to use TKinter pop-up menu in python". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Menus popups events content parameters articles up and down context value location interests functions delimiters functions examples guys partners rare methods more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info macOS Huawei NVidia OPPO Reno