What if I want a pulldown choice

A pull-down choice is a selection mechanism that only shows the choices when the pull-down arrow is clicked. A pull-down is the most compact way to display a choice of elements, and is most useful when screen space is tight. From a user perspective, a choice is most useful for a relatively large list of options, although they are also preferred when it's not necessary for the user to see all the options at all times. Figure 7.15 displays a closed choice. And figure 7.16 displays an open pull-down.

Figure 7.15 A pull-down choice, with no selection
Figure 7.16 A pull-down choice in the process of having an element selected

The use of a choice is very similar to a regular list box. Listing 7.14 displays how to create a pull-down choice.

Listing 7.14 Creating a pull-down choice import wx class ChoiceFrame(wx.Frame):

wx.Frame._init_(self, None, -1, 'Choice Example', size=(250, 200)) panel = wx.Panel(self, -1)

sampleList = ['zero', 'one', 'two', 'three', 'four', 'five',

'six', 'seven', 'eight'] wx.StaticText(panel, -1, "Select one:", (15, 20)) wx.Choice(panel, -1, (85, 18), choices=sampleList)

app = wx.PySimpleApp()



The constructor for a choice is basically identical to the one for a list box:

wx.Choice(parent, id, pos=wx.DefaultPosition, size=wx.DefaultSize, choices=None, style=0, validator=wx.DefaultValidator, name="choice")

A wx.Choice has no specific styles, but it does have a unique command event, evt_choice. Almost all of the methods in table 7.14 that apply to single-selection list boxes also apply to wx.Choice objects.

Was this article helpful?

0 0

Post a comment