Ich habe nur ein kleines problem mit dem PopUp menue. Kann man an stelle von command eine variable erstellen? Z.b. wenn man auf eine Numer klickt (siehe unten) soll die Nummer im Python Shell ausgedruckt werden.
Danke!
Gruesse,
Aleksandar
Code: Alles auswählen
from Tkinter import *
root = Tk()
w = Label(root, text="Right-click to display menu", width=40, height=20)
w.pack()
def next():
print # es soll die Nummer schreiben auf die Man geklickt hat
def do_popup(event):
popup = Menu(root, tearoff=0)
for i in range (1,20):
popup.add_command(label=i, command=next)
try:
popup.tk_popup(event.x_root+35, event.y_root+10, 0)
finally:
popup.grab_release()
w.bind("<Button-3>", do_popup)
mainloop()