-4

I am use ttkbootstarp developing a software,but i cannot custom settings the right click menus ,how can i do this?

i just wanna custom settings the right click menus ,but i cannot find the api and method in the Official site

enter image description here

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
Soul MIX
  • 11
  • 1

1 Answers1

1

Found your Problem solved on this Website: https://www.geeksforgeeks.org/right-click-menu-using-tkinter/

I have found this code:

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",    command= lambda: dosomething())
m.add_command(label = "Copy",   command= lambda: dosomething())
m.add_command(label = "Paste",  command= lambda: dosomething())
m.add_command(label = "Reload", command= lambda: dosomething())
m.add_separator()
m.add_command(label = "Rename", command= lambda: dosomething())
  
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()

enter image description here

This will be the Result of thsi code. So you can replace the dosomething with your own commands and you have your own right-click menu.