wxpython: bringing up a dialog box with a button

J

John Salerno

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

--------------

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)

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()

---------------------

and this is what I get:
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)
Hope someone can correct me here!
 
J

jean-michel bain-cornu

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
 
J

John Salerno

jean-michel bain-cornu said:
When your button gives an event, wx send two arguments : the object
itself and an event object. So you can't bind directly.

Ah, that explains it! Thank you!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top