Greg Ercolano wrote:
> Robert Arkiletian wrote:
>> def but_cb(self, widget):
>> widget.label("okay")
>> print widget.secret #this line pukes
>
> Maybe that last line should instead read:
>
> print self.but.secret
This works too:
--- snip
self.but.callback(self.but_cb, self) # pass 'self' as
userdata
self.end()
def but_cb(self, w, userdata):
print userdata.but.secret
--- snip
Apparently the thing to note about Python class methods
in this context is the first argument is always 'self',
which shifts all the arguments we're used to over one. So:
void but_cb(Fl_Widget *w, void* userdata) // 2 args in C++
def but_cb(self, w, userdata): # 3 args in python
BTW, I didn't know any of this until a few minutes ago,
having for the first time downloaded pyfltk and noodled
around with the examples. I'm pretty much a noob to python.
I have to say pyfltk is some piece of work; compiled perfectly
on my fedora3 box with no haggling, and the examples seem to work
as advertised. Hell, there's even a table.py example that uses my
Fl_Table widget.. works just like the original. And you can derive
classes too.. I'm impressed!
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk