On 5/25/07, Greg Ercolano <[EMAIL PROTECTED]> wrote:
> 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
The first arg of but_cb is already self
I think there is no need to send it twice. All class methods can
reference the class instance through self.
>
> 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!
If you like Python Greg, here are a couple of nice links. They are all
I have used to learn it.
http://www.swaroopch.info/text/Byte_of_Python:Main_Page
http://docs.python.org/tut/tut.html
--
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