[Tutor] How to allow user to choose an option from a window

Jason Massey jason.massey at gmail.com
Tue Dec 12 18:40:04 CET 2006


If you mean which type of GUI model to use you have at least two popular
choices.

Tkinter: It's bundled with Python, and there's a tutorial at:
http://www.pythonware.com/library/tkinter/introduction/
wxPython: My GUI of choice.  http://wxpython.org

A quick and dirty example in wxPython of what you wanted:

import wx

class MainWindow(wx.Frame):
    def __init__(self,parent,id,title):
        wx.Frame.__init__(self,parent,wx.ID_ANY,title,size=(200,200))
        self.radiobox = wx.RadioBox(self,wx.ID_ANY
,'Options',choices=['One','Two','Three'],style=wx.RA_SPECIFY_ROWS)

        self.Bind(wx.EVT_RADIOBOX,self.OnRadioBoxChoose,self.radiobox)
        self.Show()

    def OnRadioBoxChoose(self,event):
        choice = self.radiobox.GetStringSelection()
        wx.MessageBox("You selected: %s" % choice)

app = wx.PySimpleApp()
frame = MainWindow(None,-1,"Options")
app.MainLoop()




On 12/12/06, Urban.Landreman at co.hennepin.mn.us <
Urban.Landreman at co.hennepin.mn.us> wrote:
>
> I'm trying to allow a user to select one option from a list.
>
> My simple code works:
> OptionList = ['One', 'Two', 'Three']
> while 1:
>   print 'Here are your options:'
>   for option in OptionList:
>       print option
>   optionChosen = raw_input("Which one do you want? ")
>   if optionChosen in OptionList:
>       break
>   print "That is not a valid option.  Please re-enter your choice."
> print "You have chosen: ", optionChosen
>
> However, Now I'd like to display the options within a MsgBox-type display
> and have the user click on the option of choice.
>
> Any suggestions of a model I can adapt to accomplish this?
>
> Thanks.
>
> Urban Landreman
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061212/b28e8787/attachment.htm 


More information about the Tutor mailing list