question about wxpython CtrlList event binder: wx.EVT_LIST_ITEM_RIGHT_CLICK

Kent kent.yuan at
Tue Apr 21 23:59:18 CEST 2009

Hi Mike,

thx for the wxpython maillist link, I will give it a shot. But I would
like to paste the code snippet here as well, hope it can tell
sufficient information. (I added some comments in the class. ) Thank

class TagListCtrl(wx.ListCtrl):
    Tag list ListCtrl widget

    def __init__(self,parent,id):
        # this 'images' is not important, just icons
        images = (myGui.ICON_TAG_CUSTOM,

        # so the listctrl is in REPORT MODE

        #here are some property value init..
        self.parent = parent
        self.mainFrm = self.GetTopLevelParent() # main Frame
        il = wx.ImageList(24,24)
        for image in images:


        #popup menu
        self.popmenu = None

        # bind the events
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelect) #selected,
e.g. left click

        self.Bind(wx.EVT_SIZE, self.OnSize)
        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.onTagMgmt,self)

        #this function load the item data into the List

    #this is the function
    def onTagMgmt(self,event):
        tagId = event.GetData()
        # following codes are omitted. just some business logic stuff.
checking the tagId, making decision of showing popup menu items...


On Apr 21, 11:24 pm, Mike Driscoll <kyoso... at> wrote:
> On Apr 21, 3:35 pm, Kent <kent.y... at> wrote:
> > Hi there,
> > I wrote a desktop application with wxPython2.8. And got a problem.
> > Hope here someone can give some hint. Thanks in advance.
> I recommend joining the wxPython mailing list and posting there. The
> guys there are great and can probably help you out. See
> > There was a ListCtrl (lc) in my GUI, and it was a bit long, so that
> > there would be some blank space below ("empty area") in case there
> > were only a few items.
> > I bind a function on the event wx.EVT_LIST_ITEM_RIGHT_CLICK, when user
> > rightclick on the lc item, my function was triggered, and open a popup
> > menu.
> > Depends on the item user clicked, the menu items can be different. I
> > checked the event.getData(), to decide which menu item will show to
> > user. That is, if user right click on the "empty area", the
> > event.getData() will be 0. I wrote the appl. under Linux, and tested,
> > it worked as what I expected.
> > However, today someone reported a bug, said, under Windows XP, right
> > clicking on the items of lc, it works fine, but if on the "empty area"
> > of the lc, nothing happened, no popup menu. I tested under WINXP, the
> > function was not triggered at all when I right-clicked on the "empty
> > area".
> > I tried to bind wx.EVT_RIGHT_DOWN(UP) to the lc, but the function
> > cannot be triggered under Linux.  any suggestion?
> > Thanks
> > regards,
> > Kent
> If you join the wxPython list, they'll probably ask for a small
> runnable sample. Here's some instructions for how to do that:
> It would be good to know what mode you are using for your ListCtrl.
> List view, report, icon or what? The demo doesn't have any white space
> at the end, so I can't test this easily. Are you using a sizer to hold
> the widget?
> - Mike

More information about the Python-list mailing list