Sorry if this is a bit off topic as it's a pyFLTK question.
I cannot seem to access any of the attributes of my Fl_Button subclass
in a callback through the widget variable.
Shouldn't the widget variable in the callback refer to a MyButton object?
#!/usr/bin/python
from fltk import *
class MyButton(Fl_Button):
def __init__(self,x,y,w,h,label=None):
Fl_Button.__init__(self,x,y,w,h,label)
self.secret="ssss"
class MyWindow(Fl_Window):
def __init__(self,x,y,w,h,label=None):
Fl_Window.__init__(self,x,y,w,h,label)
self.begin()
self.but=MyButton(30,30,50,50)
self.but.callback(self.but_cb)
self.end()
def but_cb(self, widget):
widget.label("okay")
print widget.secret #this line pukes
win=MyWindow(200,200,200,200)
win.show()
Fl.run()
When I click on the MyButton object I get this error
Traceback (most recent call last):
File "ginhert.py", line 23, in but_cb
print widget.secret
File "/usr/lib/python2.3/site-packages/fltk.py", line 91, in <lambda>
__getattr__ = lambda self, name: _swig_getattr(self, Fl_Widget, name)
File "/usr/lib/python2.3/site-packages/fltk.py", line 38, in _swig_getattr
raise AttributeError,name
AttributeError: secret
After trying some more testing, it seems that the widget variable is
not even an Fl_Button object but rather an Fl_Widget. In C++ I would
employ a cast but I don't think I can do this in Python. Any help is
appreciated.
--
Robert Arkiletian
Eric Hamber Secondary, Vancouver, Canada
Fl_TeacherTool http://www3.telus.net/public/robark/Fl_TeacherTool/
C++ GUI tutorial http://www3.telus.net/public/robark/
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk