[wxPython-users] Bind arguments
Matt Webster
matt at cudadog.com
Sun Mar 16 10:53:02 PDT 2008
Hello. I'm working from tutorial code (http://wiki.wxpython.org/AnotherTutorial
) building the calculator and came across this:
self.Bind(wx.EVT_BUTTON, self.OnSeven, id=1)
self.Bind(wx.EVT_BUTTON, self.OnEight, id=2)
self.Bind(wx.EVT_BUTTON, self.OnNine, id=3)
...
OnSeven, OnEight, and OnNine all have the same code except for what
they display:
def OnSeven(self, event):
if self.formula:
self.display.Clear()
self.formula = False
self.display.AppendText('7')
Being lazy and clever, I thought I would change the functions to all
be the same and just pass a new value:
self.Bind(wx.EVT_BUTTON, self.OnShow('7'), id=1)
self.Bind(wx.EVT_BUTTON, self.OnShow('8'), id=2)
self.Bind(wx.EVT_BUTTON, self.OnShow('9'), id=3)
...
def OnShow(self, event, displayText):
if self.formula:
self.display.Clear()
self.formula = False
self.display.AppendText(displayText)
When I run it, I get the following error:
Traceback (most recent call last):
File "./x.py", line 184, in <module>
app = MyApp(0)
File "/BinaryCache/wxWidgets/wxWidgets-11~57/Root/System/Library/
Frameworks/Python.framework/Versions/2.5/Extras/lib/python/wx-2.8-mac-
unicode/wx/_core.py", line 7757, in __init__
File "/BinaryCache/wxWidgets/wxWidgets-11~57/Root/System/Library/
Frameworks/Python.framework/Versions/2.5/Extras/lib/python/wx-2.8-mac-
unicode/wx/_core.py", line 7354, in _BootstrapApp
File "./x.py", line 179, in OnInit
frame = MyFrame(None, -1, 'calculator.py')
File "./x.py", line 52, in __init__
self.Bind(wx.EVT_BUTTON, self.OnShow('7'), id=1)
TypeError: OnShow() takes exactly 3 arguments (2 given)
After fooling around for a few hours with this, I'm getting to the
point where I believe the Bind() doesn't allow functions with
arguments. Every example I've pulled on the web supports this but so
far I haven't found any docs that say this too.
Ideas?
More information about the wxpython-users
mailing list