bringing up a dialog box with a button

Thanks very much! Is OnShowDialog() being overridden, or is it a
method you just created yourself? (Did a search in the docs and didn't
find it, but it looks like an "official" name :slight_smile:

John

路路路

---------- Forwarded message ----------
From: Robin Dunn <robin@alldunn.com>
To: wxPython-users@lists.wxwidgets.org
Date: Tue, 13 Jun 2006 13:26:51 -0700
Subject: Re: [wxPython-users] bringing up a dialog box with a button
John Salerno wrote:

I'm not exactly sure how to call the method ShowModal(). This is what
I have so far:

try this instead:

import wx

class InputForm(wx.Frame):

   def __init__(self, parent=None, id=wx.ID_ANY, title=''):
       wx.Frame.__init__(self, parent, id, title)
       panel = wx.Panel(self)

       btnModal = wx.Button(panel, -1, 'Modal')
       self.Bind(wx.EVT_BUTTON, self.OnShowDialog, btnModal)

   def OnShowDialog(self, evt):
       dialog = wx.Dialog(self, -1, 'Modal Dialog')
       dialog.ShowModal()
       dialog.Destroy()

class MyApp(wx.App):

   def OnInit(self):
       frame = InputForm(title='Data Entry Form')
       self.SetTopWindow(frame)
       frame.Show()
       return True

app = MyApp(redirect=False)
app.MainLoop()

Also, are there any predefined classes that you can use for commonly
used objects, such as a dialog box with an OK and Cancel button
already in it, that behave as you would expect when clicked?

Yep. Look in the demo under "Common Dialogs"

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

John Salerno wrote:

Thanks very much! Is OnShowDialog() being overridden, or is it a
method you just created yourself? (Did a search in the docs and didn't
find it, but it looks like an "official" name :slight_smile:

I just made it up. The common convention is to use On names for event handlers as well as for various callbacks that are overridden from base classes. In this case it is an event handler because it is used in the self.Bind call.

路路路

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!