Traceback (most recent call last):
File "D:\python\bx\bxgui.py", line 120, in test
self.sendmail()
AttributeError: 'MyFrame' object has no attribute 'sendmail'
Thanks!
Hmmm...I think you're leaving something out here. This should "just work". I whipped together a quick sample and it works:
<code>
import wx
class MyForm(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Button Tutorial")
# Add a panel so it looks the correct on all platforms
panel = wx.Panel(self, wx.ID_ANY)
btn = wx.Button(panel, wx.ID_ANY, 'Push me!')
self.Bind(wx.EVT_BUTTON, self.onButton, btn)
def sendmail(self):
print "in sendmail"
def onButton(self, event):
print "in onButton"
self.sendmail()
# Run the program
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = MyForm().Show()
app.MainLoop()
</code>
What platform are you on? Python and wxPython versions may be helpful as well. I am using wxPython 2.8.9.1 (unicode), Python 2.5.2 on Windows XP.
Could it be possible that this is something like you added
the definition of sendmail and then didn't save your program (with
this new addition) when you tried to run it? Because it seems right.
···
On Wed, Jan 14, 2009 at 11:13 AM, Pieter Provoost <pieterprovoost@gmail.com> wrote:
I'm trying to call a method from an event handler, but that doesn't seem to
work. What am I doing wrong? Please note that I'm a (wx)Python beginner...
Traceback (most recent call last):
File "D:\python\bx\bxgui.py", line 120, in test
self.sendmail()
AttributeError: 'MyFrame' object has no attribute 'sendmail'
Further to the other responses you are receiving from Mike, C M, may I
give a modest recommendation ?
In my humble opinion - I'm a green horn too - I prefer not to use the
facility (*args, **kwds) which is great but maybe too convenient for a
starter. I believe it is more educational to explicitely write the
positional parameters and the named parameters. It obliges us (the
newbies) to look at the documentation and to learn more in depth. So,
when we write something like:
def __init__(self, row, column):
we know that self refers to the instance and that row and colum are 2
parameters. This comes handy when receiving error messages of the
kind:
"function f expects 2 arguments, 3 received" or that sort of thing.
Furthermore, there are already so many functions or methods (within
classes) that have default value for their parameters in the form:
param = wx.DEFAULT_PARAM_VALUE
So, when calling functions or methods, my recommendation is to be
verbose in the parameter passing.
Hope nobody minds me giving a personal opinion.
Enjoy Python / wxPython as much as I do. I guess I might book 100 hours soon.
Welcome to the group.
Rene
···
On Wed, Jan 14, 2009 at 5:13 PM, Pieter Provoost <pieterprovoost@gmail.com> wrote:
I'm trying to call a method from an event handler, but that doesn't seem to
work. What am I doing wrong? Please note that I'm a (wx)Python beginner...
Traceback (most recent call last):
File "D:\python\bx\bxgui.py", line 120, in test
self.sendmail()
AttributeError: 'MyFrame' object has no attribute 'sendmail'
This appears to be an indentation issue. While preparing the minimal example (which works) below, I noticed that the indentation is wrong in notepad. In eric4 and notepad++ it appears to be fine though. I repaired the code in notepad and now it works…
AttributeError: ‘MyFrame’ object has no attribute ‘sendmail’
Thanks!
Hmmm…I think you’re leaving something out here. This should “just work”. I whipped together a quick sample and it works:
import wx
class MyForm(wx.Frame):
def init(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Button Tutorial")
# Add a panel so it looks the correct on all platforms
panel = wx.Panel(self, wx.ID_ANY)
btn = wx.Button(panel, wx.ID_ANY, 'Push me!')
self.Bind(wx.EVT_BUTTON, self.onButton, btn)
def sendmail(self):
print "in sendmail"
def onButton(self, event):
print "in onButton"
self.sendmail()
# Run the program
if name == “main”:
app = wx.PySimpleApp()
frame = MyForm().Show()
app.MainLoop()
What platform are you on? Python and wxPython versions may be helpful as well. I am using wxPython 2.8.9.1 (unicode), Python 2.5.2 on Windows XP.
Department of Ecosystem Studies
Centre for Estuarine and Marine Ecology (CEME)
Netherlands Institute of Ecology (NIOO-KNAW)
Korringaweg 7, 4401 NT Yerseke
The Netherlands
+32-478-574420 (Belgium)
+31-113-577472 (The Netherlands)
skype pieterprovoost
In my humble opinion - I'm a green horn too - I prefer not to use the
facility (*args, **kwds) which is great but maybe too convenient for a
starter. I believe it is more educational to explicitely write the
positional parameters and the named parameters.
In general, I agree.
So, when calling functions or methods, my recommendation is to be
verbose in the parameter passing.
I also agree.
However:
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
I think this is the way to go -- it says: make this class take exactly the same arguments as a wx.Frame -- that is what you want here, and it makes more sense than repeating all the wx.Frame arguments twice in this code.
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Thank you Chris for your comments.
Very well pointed.
I appreciate your care.
All the best,
Rene
···
On Wed, Jan 14, 2009 at 10:47 PM, Christopher Barker <Chris.Barker@noaa.gov> wrote:
Rene Heymans wrote:
In my humble opinion - I'm a green horn too - I prefer not to use the
facility (*args, **kwds) which is great but maybe too convenient for a
starter. I believe it is more educational to explicitely write the
positional parameters and the named parameters.
In general, I agree.
So, when calling functions or methods, my recommendation is to be
verbose in the parameter passing.
I also agree.
However:
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
I think this is the way to go -- it says: make this class take exactly the
same arguments as a wx.Frame -- that is what you want here, and it makes
more sense than repeating all the wx.Frame arguments twice in this code.
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception