mayhew
mayhew

Reputation: 5

How can I create a multi-line wx.ComboCtrl in wxPython?

Setting the wx.TE_MULTILINE style flag on the ComboCtrl itself or the associated TextCtrl results in no change after a Refresh(). After quite some time Googling, I saw several sources that stated that apparently creating multiline Combo Box is complicated/impossible, yet creating a multi-line Combo Ctrl was simple enough that they didn't mention how it is done. Clearly I'm doing something wrong here, but the question is what?

class MultiCombo(wx.combo.ComboCtrl):
    def __init__(self, parent):
        wx.combo.ComboCtrl.__init__(self, parent, style=wx.TE_MULTILINE)

multicombo = MultiCombo(parent_panel)
##  multicombo.SetWindowStyle(wx.TE_MULTILINE)
multicombo.GetTextCtrl().SetWindowStyle(wx.TE_MULTILINE)
multicombo.GetTextCtrl().Refresh()
multicombo.Refresh()

Note: code provided is a pared-down example - the actual code looks slightly different.

Upvotes: 0

Views: 553

Answers (1)

SteveL
SteveL

Reputation: 1821

The problem is that according to the documentation:

Note that alignment styles (wxTE_LEFT, wxTE_CENTRE and wxTE_RIGHT) can be changed dynamically after control creation on wxMSW and wxGTK. wxTE_READONLY, wxTE_PASSWORD and wrapping styles can be dynamically changed under wxGTK but not wxMSW. The other styles can be only set during control creation.

So rather than changing the style you need to use wxComboCtrl::SetTextCtrlStyle as demonstrated in the documentation.

Upvotes: 1

Related Questions