Introduction

Sometimes you need to get user input or display results from a simple command and just want a program to start, do a linear set of steps and then exit without bothering with the main GUI event loop. Function wrappers were added to the common system dialogs in wxPython 2.4. Besides making the dialogs easier to use in normal programs, it makes coding a linear set of steps much simpler.

Process Overview

Use the new function wrappers in wxPython.lib.dialogs with wxPython 2.4 or higher.

Code Sample

This program is a port of the EasyGUI demo.

   1 import wx
   2 
   3 app = wx.App(0)
   4 
   5 while 1:
   6   
   7     wx.MessageBox("Hello, world!")
   8 
   9     msg = "What is your favorite flavor?"
  10     title = "Ice Cream Survey"
  11     choices = ["Vanilla", "Chocolate", "Strawberry", "Rocky Road"]
  12     dlg = wx.SingleChoiceDialog(None, msg, title, choices)
  13 
  14     if dlg.ShowModal() == wx.ID_OK:
  15         wx.MessageBox("Survey Result is " + dlg.GetStringSelection())
  16     dlg.Destroy()
  17     
  18     msg = "Do you want to continue?"
  19     title = "Please Confirm"
  20     if wx.MessageBox(msg, title, wx.YES_NO) == wx.NO:
  21         break
  22 
  23 # There is cleanup that happens after the single iteration 
  24 # of MainLoop that should be done after the dialogs are finished.
  25 app.MainLoop()

LinearApplications (last edited 2008-03-11 10:50:39 by localhost)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.