Core Windows/Controls → Choice
Overview = """\
A Choice control is used to select one of a list of strings. Unlike a listbox,
only the current selection is visible until the user pulls down the menu of
choices.
This demo illustrates how to set up the Choice control and how to extract the
selected choice once it is selected.
Note that the syntax of the constructor is different than the C++ implementation.
The number of choices and the choice array are consilidated into one python list.
"""
import wx
class Frame(wx.Frame):
def __init__(
self, parent, id=-1, title='Choice', 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)
StaticText = wx.StaticText(Panel, -1, 'Programming Language', (15, 10))
StaticText = wx.StaticText(Panel, -1, 'Select One', (15, 50))
Languages = [ 'C', 'C++', 'Python', 'Java', 'Ruby', 'Perl' ]
self.Choice = wx.Choice(Panel, -1, (100, 50), choices=Languages)
self.Bind(wx.EVT_CHOICE, self.OnChoice, self.Choice)
def OnChoice(self, event):
wx.MessageBox('You selected %s' % event.GetString())
def TestFrame():
app = wx.PySimpleApp()
frame = Frame(parent=None)
frame.Centre()
frame.Show()
app.MainLoop()
if __name__ == '__main__':
TestFrame()