wxpython: bringing up a dialog box with a button

jean-michel bain-cornu jmbc at nospam.fr
Tue Jun 13 16:19:12 EDT 2006


John Salerno a écrit :
> 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')
>         dialog = wx.Dialog(self, -1, 'Modal Dialog')
>         self.Bind(wx.EVT_BUTTON, dialog.ShowModal, btnModal)
Don't bind directly ShowModal to EVT_BUTTON
> Traceback (most recent call last):
>   File "C:\Python24\Lib\site-packages\wx-2.6-msw-ansi\wx\_windows.py", 
> line 688, in ShowModal
>     return _windows_.Dialog_ShowModal(*args, **kwargs)
> TypeError: Dialog_ShowModal() takes exactly 1 argument (2 given)
When your button gives an event, wx send two arguments : the object 
itself and an event object. So you can't bind directly.
What you have to do is to use an intermediate method. Something like:
	self.dialog = wx.Dialog(self, -1, 'Modal Dialog')
         self.Bind(wx.EVT_BUTTON, self.OnClick, b)
     def OnClick(self, event):
         self.dialog.ShowModal()

Regards,
jm



More information about the Python-list mailing list