]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/Choice.py
   4 #--------------------------------------------------------------------------- 
   6 class TestChoice(wx
.Panel
): 
   7     def __init__(self
, parent
, log
): 
   9         wx
.Panel
.__init
__(self
, parent
, -1) 
  11         sampleList 
= ['zero', 'one', 'two', 'three', 'four', 'five', 
  12                       'six', 'seven', 'eight'] 
  14         wx
.StaticText(self
, -1, "This example uses the wxChoice control.", (15, 10)) 
  15         wx
.StaticText(self
, -1, "Select one:", (15, 50), (75, -1)) 
  16         self
.ch 
= wx
.Choice(self
, -1, (100, 50), choices 
= sampleList
) 
  17         self
.Bind(wx
.EVT_CHOICE
, self
.EvtChoice
, self
.ch
) 
  20     def EvtChoice(self
, event
): 
  21         self
.log
.WriteText('EvtChoice: %s\n' % event
.GetString()) 
  22         self
.ch
.Append("A new item") 
  24         if event
.GetString() == 'one': 
  25             self
.log
.WriteText('Well done!\n') 
  28 #--------------------------------------------------------------------------- 
  30 def runTest(frame
, nb
, log
): 
  31     win 
= TestChoice(nb
, log
) 
  34 #--------------------------------------------------------------------------- 
  37 A Choice control is used to select one of a list of strings. Unlike a listbox,  
  38 only the current selection is visible until the user pulls down the menu of  
  41 This demo illustrates how to set up the Choice control and how to extract the 
  42 selected choice once it is selected.  
  44 Note that the syntax of the constructor is different than the C++ implementation. 
  45 The number of choices and the choice array are consilidated into one python  
  50 if __name__ 
== '__main__': 
  53     run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])