[Tutor] Popup menu for items in a tkinter listbox

Ellen Reitmayr ellen.reitmayr at relevantive.de
Mon Mar 15 12:19:50 EST 2004


hi,

I'm trying to set up an 'add contact from addressbook' dialog with
tkinter. There are three listboxes on the right side, showing the
selected contacts (to, cc, bcc). 
Now I want to add a popup menu to the single entries of each list in
order to remove the selected item. But I'm faces several problems:

- I bound <button-3> with each of the three listboxes to invoke the
popup, and <button-1> with the menu to invoke the remove-method: How do
I know which listbox is the target list? 'event.widget' does not work,
as the menu is the widget. Do I have to compare the x/y-coordinates? Or
is there a simpler way to identify the widgets at the current mouse
position (I did not use a canvas, so find_overlapping(x1,y1,x2,y2) does
not work).
- But actually I'm not just interested in the whole list, but in the
list entries. Is there a way to bind the popups to the list entries, not
to the whole list? And if that is not possible - How can I make a list
item be selected when I right-click it (if I do not know the index)?

Maybe someone can help me, or tell me were to find a code example for
this problem?

Thanks and have a nice day,
ellen

-----------------------------------------------

def popup(event):
    removeMenu.post(event.x_root, event.y_root)

def removeContact(event):
	# ???? how can I refer to the correct list/list item??

#
#[....]
#

removeMenu = Menu(root, tearoff=0)
removeMenu.add_command(label="Entfernen",)
removeMenu.bind("<Button-1>",removeContact)

toList.bind("<Button-3>",popup)
ccList.bind("<Button-3>",popup)
bccList.bind("<Button-3>",popup)



-- 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.python.org/pipermail/tutor/attachments/20040315/8d753050/attachment.bin


More information about the Tutor mailing list