File "ui.py", line 15, in __init__
EVT_BUTTON(self, XRCID("button_1"), self.Hello)
AttributeError: 'Dialog' object has no attribute 'Hello'
when running my application...
which does this:
class Dialog(wxDialogPtr):
def __init__(self, parent, resource):
w = resource.LoadDialog(parent, 'Dialog')
wxDialogPtr.__init__(self, w.this)
self.thisown = 1
self.Center()
EVT_BUTTON(self, XRCID("button_1"), self.Hello)
def Hello(self, evt):
print "hello!"
...
--> I can't figure out why the class Dialog has no method Hello...printing the self.__dict__ indeed shows that Hello is not bound...
any idea?
It looks correct above but check your indentation and watch out for tabs.
strange...because the class __dict__ shows the method, not the instance...
E:\test-xrc>python ui.py
{'__module__': '__main__', 'Hello': <function Hello at 0x0098DB30>, '__init__':
<function __init__ at 0x009A61B0>, '__doc__': None}
Traceback (most recent call last):
File "ui.py", line 44, in ?
testPreferencesDialog()
File "ui.py", line 39, in testPreferencesDialog
app = MyApp(0)
File "ui.py", line 23, in __init__
wxApp.__init__(self, num)
File "C:\Python23\Lib\site-packages\wx\_core.py", line 5243, in __init__
self._BootstrapApp()
File "C:\Python23\Lib\site-packages\wx\_core.py", line 4931, in _BootstrapApp
return _core_.PyApp__BootstrapApp(*args, **kwargs)
File "ui.py", line 33, in OnInit
dialog = Dialog(None, resource)
File "ui.py", line 15, in __init__
EVT_BUTTON(self, XRCID("button_1"), self.Hello)
AttributeError: 'Dialog' object has no attribute 'Hello'
I am new to python, so this maybe a problem with me
On line #1 the dialog instance is created, but the UI Object is not. This is called 2-phase create in the wx docs, and is provided for special situations where some things may need to be done in the object before the UI object is created, like setting extended style flags. Normally you would call Create yourself to do the actual creation of the UI object.
Line #2 calls Create for you and loads the controls defined in the resource onto the dialog.
Line #3 transfers the "guts" of the pre instance into self, so self becomes the dialog.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
On line #1 the dialog instance is created, but the UI Object is not. This is called 2-phase create in the wx docs, and is provided for special situations where some things may need to be done in the object before the UI object is created, like setting extended style flags. Normally you would call Create yourself to do the actual creation of the UI object.
Line #2 calls Create for you and loads the controls defined in the resource onto the dialog.
Line #3 transfers the "guts" of the pre instance into self, so self becomes the dialog.