Choose from the following list

If, instead of all the freedom that comes with being able to enter any thing that enters his head, you want the user to only be able to select a choice from a provided list, you can use the wx.SingleChoiceDialog class. A simple usage is shown here:

dlg = wx.SingleChoiceDialog(None,

'What version of Python are you using?', 'Single Choice',

['1.5.2', '2.0', '2.1.3', '2.2', '2.3.1'], if dlg.ShowModal() == wx.ID_OK:

response = dlg.GetStringSelection()

Figure 2.12 shows the resulting dialog box. The parameters are similar to the text entry dialog, except that instead of passing a string default text, you pass a list of strings that are displayed in the list. There are two ways that you can get the returned selection. The method GetSelection() returns the index of the user selection, while GetStringSelection() returns the actual string selected.

Figure 2.12 The

SingleChoiceDialog window, allowing a user to choose from a predefined list

Figure 2.12 The

SingleChoiceDialog window, allowing a user to choose from a predefined list

Was this article helpful?

0 0

Post a comment