Python equivilant to msgbox()

Andre Roberge andre.roberge at gmail.com
Mon Feb 13 08:16:52 EST 2006


On 2/13/06, Peter Decker <pydecker at gmail.com> wrote:
> On 12 Feb 2006 17:27:56 -0800, André <andre.roberge at gmail.com> wrote:
>
> > It's also possible to something like that with wxPython.  Try:
> > import wx
> > app = wx.PySimpleApp()
> > dlg = wx.TextEntryDialog(None, 'Enter value', 'Title', '')
> > if dlg.ShowModal() == wx.ID_OK:
> >     val = dlg.GetValue()  # this line should be indented
> > dlg.Destroy()
> > print "you have entered %s" % val
>
> That's the sort of butt-ugly code that got me convinced that Dabo is
> the way to go. To get a simple message box, you have to create it,
> show it, check a return value against an ugly constant (make sure you
> don't forget an use wx.OK instead!), and then remember to destroy it
> or your app will hang.
>
> The same code in Dabo is:
>
> val = dabo.ui.getString("Enter value", "Some Title")
> if val in None:
>    print "You canceled"
> else:
>    print "You entered %s" % val
>
> Look at both examples, and tell me which looks more Pythonic to you.

While I agree that dabo's version is more Pythonic than wxPython, my
understanding is that dabo is built on top of wxPython.  There are
other framework (wax, anygui) that also aim to make the coding "more
pythonic", hiding "ugly" wxPython details.  Personnally, I am hesitant
to start using an extra layer on top of wxPython, with no guarantee
that it will be always updated.  Ideally, something like dabo+wxPython
would become part of the standard Python distribution.

The original post was asking if it was possible to have such message
dialogs using Python, without having a full gui app.  I'd say that the
answer is yes... and that one has a lot of options, depending on how
many packages one is ready to download.

André



More information about the Python-list mailing list