app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import tkinter from tkinter import * root = Tk() L = Label(root, text ="Right-click to display menu", width = 40, height = 20) L.pack() m = Menu(root, tearoff = 0) m.add_command(label ="Cut") m.add_command(label ="Copy") m.add_command(label ="Paste") m.add_command(label ="Reload") m.add_separator() m.add_command(label ="Rename") def do_popup(event): try: m.tk_popup(event.x_root, event.y_root) finally: m.grab_release() L.bind("<Button-3>", do_popup) mainloop() |