The wxTreeCtrl has a bug in its arrow keys.

What Objects are Involved

Uh, the wxTreeCtrl

Process Overview

The "correct" keystrokes for a tree control are:

Special Concerns

The wxTreeCtrl gets Left wrong. It does not opt to collapse.

The following sample works if you have inherited the tree control; otherwise refactor the 'self.' and adjust the binding. I added this to the ListAndTreeControls example.

Code Sample

        def __init__(
                ... blah blah blah
                EVT_KEY_DOWN(self, self.OnKey)

        def OnKey(self, event):
            'On <Left>, if the current item is expanded, collapse it'
            key = event.KeyCode()
            if key == WXK_LEFT:
                ID = self.GetSelection()
                if self.IsExpanded(ID):


It'd be nice if someone promoted this patch back up to the source (WxGtk) instead of only fixing it down here in the python.


It seems to have been fixed now.. (well, the bindings are correct in the latest wxPython demo, and I can't see anything resembling your fix in the code)


WxTreeControlArrowKeyBug (last edited 2008-03-11 10:50:17 by localhost)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.