yadav2152003s

Create Right Click Menu

Aug 21st, 2020
1,357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. import tkinter
  2. from tkinter import *
  3.  
  4. root = Tk()
  5.  
  6. L = Label(root, text ="Right-Click to Display Menu",
  7.           width = 40, height = 20)
  8. L.pack()
  9.  
  10. m = Menu(root, tearoff = 0)
  11. m.add_command(label ="Cut")
  12. m.add_command(label ="Copy")
  13. m.add_command(label ="Paste")
  14. m.add_command(label ="Reload")
  15. m.add_separator()
  16. m.add_command(label ="Rename")
  17.  
  18. def do_popup(event):
  19.     try:
  20.         m.tk_popup(event.x_root, event.y_root)
  21.     finally:
  22.         m.grab_release()
  23.  
  24. L.bind("<Button-3>", do_popup)
  25.  
  26. mainloop()
  27.  
Advertisement
Add Comment
Please, Sign In to add comment