Red de conocimiento informático - Conocimiento sistemático - ¡Por favor haga preguntas! ¿Cómo hacer un menú contextual de un cuadro de lista en Python Tkinter? Quiero hacer clic derecho en un elemento para mostrar un menú.

¡Por favor haga preguntas! ¿Cómo hacer un menú contextual de un cuadro de lista en Python Tkinter? Quiero hacer clic derecho en un elemento para mostrar un menú.

Puedes consultar este

¿Dónde? ¿tkinter? ¿importar? *

¿Raíz? =?Tk()

Root.title('Pruebe el menú contextual del cuadro de texto')

root.resizable(False, false)

root .geometry (" 300 x102020 ")

Etiqueta (root, Text= 'Aquí está el cuadro de texto recién generado, pruébalo'). wrap(sides="top")

etiqueta(raíz). embalaje(side="top")

mostrar? =?Variable de cadena()

¿Empezando? =?Entry(root, textvariable=show,?width="30")

Entry.pack()

¿Clase? Parte:

def? onPaste(self):

Pruebe:

self.text? =?root.clipboard_get()

¿Excepto? Error de TCL:

Pass

show.set(str(self.text))

def? onCopy(self):

self.text? =?Entry.get()

raíz .portapapeles _ append(self . texto)

def? onCut(self):

self.onCopy()

Pruebe:

Entry.delete('sel.first ',? sel.last ')

¿Excepto? Error de TCL:

¿Pasar

sección? =?Sección()

¿Menú? =?menu(root,tear=0)

Menu.add_command(label="copiar ",?command=section.onCopy)

menu.add_separator()

Menu.add_command(label= "pegar",?command=section.onPaste)

menu.add_separator()

Menu.add_command(label= "cortar", ? comando=sección.onCut)

def? Menú emergente (evento):

menu.post(event.x_root,?event.y_root)

entry bind(" <Button-3 >,?popupmenu)

p>

raíz.mainloop()