On 5/25/07, Greg Ercolano <[EMAIL PROTECTED]> 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
Actually it doesn't work in the case of a shared callback. I think a
callback needs to be able to reference the widget that the event
occured for. Here is a hackish solution but my question still remains
#!/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=""
class MyWindow(Fl_Window):
def __init__(self,x,y,w,h,label=None):
Fl_Window.__init__(self,x,y,w,h,label)
self.pack=Fl_Pack(0,0,w,h)
self.array=[] #create an empty array
for x in range(0,3):
self.array.append(MyButton(0,0,0,50))
self.array[x].callback(self.but_cb)
self.array[x].callback(self.but_cb, x) #pass x as userdata
self.array[x].secret=chr(65+x)
self.pack.end()
self.end()
def but_cb(self, widget, userdata):
widget.label("okay")#works because label is method of Fl_Widget
print self.array[userdata].secret #this works
#print widget.secret #this still pukes
win=MyWindow(200,200,200,200)
win.show()
Fl.run()
>
>
> PS. Where are all the braces??
> *WHAT HAS SCIENCE DONE??*
> ;) ;)
Leading whitespace matters! No more improperly indented code.
--
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