Core Windows/Controls → ComboBox
Overview = """\
A ComboBox is like a combination of an edit control and a listbox. It can be
displayed as static list with editable or read-only text field; or a drop-down
list with text field; or a drop-down list without a text field.
Normally, ComboBox have be created for read-only controls. Meanwhile it can be
dynamically created (that is, it is initially empty but then we 'grow' it out of
program-supplied data).
Finally, this demo shows how event handling can differ.
EVT_TEXT_ENTER events, in which text is typed in and then ENTER is hit by the user.
EVT_TEXT can also be processed, but in that case the event is generated every time
that the user hits a key in the ComboBox entry field.
"""
import wx
class Frame(wx.Frame):
def __init__(
self, parent, id=-1, title='ComboBox', pos=wx.DefaultPosition,
size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE
):
wx.Frame.__init__(self, parent, id, title, pos, size, style)
self.SetIcon(wx.Icon('wxWidgets.ico', wx.BITMAP_TYPE_ICO))
Panel = wx.Panel(self, -1)
wx.StaticText(Panel, -1, "wx.ComboBox control", (8, 10))
wx.StaticText(Panel, -1, "Select one:", (15, 50), (75, 18))
Languages = ['C', 'C++', 'Java', 'Perl', 'Ruby']
ComboBox = wx.ComboBox(Panel, -1, 'Please Select', (90, 50), (95, -1),
Languages, wx.CB_DROPDOWN|wx.TE_PROCESS_ENTER)
self.Bind(wx.EVT_COMBOBOX, self.OnComboBox, ComboBox)
self.Bind(wx.EVT_TEXT, self.OnText, ComboBox)
self.Bind(wx.EVT_TEXT_ENTER, self.OnTextEnter, ComboBox)
# Append one item which has some client data
ComboBox.Append('Python', 'I Like Zone Of Python!')
def OnComboBox(self, event):
ComboBox = event.GetEventObject()
ClientData = ComboBox.GetClientData(event.GetSelection())
wx.MessageBox('You selected %s with client data: %s'% (event.GetString(), ClientData), 'Prompt')
def OnText(self, event):
pass
# wx.MessageBox('You input %s' % event.GetString(), 'Prompt')
# wx.TE_PROCESS_ENTER
# Capture events when the user types something into the control then
# hits ENTER.
def OnTextEnter(self, event):
wx.MessageBox('You typed %s' % event.GetString(), 'Prompt')
def TestFrame():
app = wx.PySimpleApp()
frame = Frame(parent=None)
frame.Centre()
frame.Show()
app.MainLoop()
if __name__ == '__main__':
TestFrame()