Hi,

I would like to configure my wxcombox in a way that when it gets the focus, it automaticly opens his listpart.

Any ideas ?

tia

Rony

Dani AI

Generated

A simple, portable way to make a wx.ComboBox open its drop‑down when it receives focus is to bind the focus event and then call the control's popup method from the focus handler. As noted, there are widget extensions that can provide extra behaviors, but the plain wxPython approach below works on most versions if you allow for small API/name differences across releases.

import wx

class TestFrame(wx.Frame):
    def __init__(self):
        super(TestFrame, self).__init__(None, title="Combo focus popup")
        panel = wx.Panel(self)
        self.combo = wx.ComboBox(panel, choices=["One", "Two", "Three"])
        self.combo.Bind(wx.EVT_SET_FOCUS, self.OnComboFocus)

        s = wx.BoxSizer(wx.VERTICAL)
        s.Add(self.combo, 0, wx.ALL | wx.EXPAND, 10)
        panel.SetSizer(s)
        self.Show()

    def OnComboFocus(self, event):
        # let native focus handling finish, then show popup
        wx.CallAfter(self._show_popup)
        event.Skip()

    def _show_popup(self):
        for name in ("ShowPopup", "Popup"):
            fn = getattr(self.combo, name, None)
            if callable(fn):
                fn()
                break

if __name__ == "__main__":
    app = wx.App(False)
    TestFrame()
    app.MainLoop()

Notes and troubleshooting:

  • CallAfter is important: trying to show the popup immediately inside the focus handler can interfere with native mouse/click focus handling.
  • Use event.Skip() so the default focus behavior still runs.
  • Different wx versions/platforms expose the popup method under different names; the code above checks common variants.
  • Be aware of UX/accessibility: auto-opening on focus can be surprising for keyboard users or screen readers. If needed, only open for keyboard focus (track recent mouse events) or restrict this behaviour to specific workflows.

Recommended Answers

All 2 Replies

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.