[Tkinter-discuss] Creating a new widget class
donaldkenney at gmail.com
Sun Aug 3 23:34:42 CEST 2008
I wonder if someone who understands Python and Tkinter a bit better than I
could help me out. Basically, I'm trying to encapsulate the kind of messy
stuff associated with setting up a listbox with a scrollbar in a Python
class. From my probably incredibly naive point of view, it doesn't look too
class ScrolledList(Frame,Listbox,Scrollbar) :
#At this point we have a template for objects that have all the
#attributes and methods of Frames,Listboxes,and Scrollbars. For
#names that occur in all, the Frame version takes precedence over
#the Listbox version and that in turn takes precedence over
def __init__ (self, Tkobject, height=4, width=50) :
#This code is executed whenever a new scrolled list object is
self.f = Frame(Tkobject)
s = Scrollbar(self.f,orient=VERTICAL)
self.l = Listbox(self.f, height=height, width=width,
#We have now created a frame, scrollbar and listbox
s.pack(side=RIGHT, fill=Y); self.l.pack()
#And configured the listbox and scrollbar to interact
And it creates a Tkinter object with a gazillion attributes. Unfortunately
tk isn't one of them. When I try to invoke the methods, I am informed that
the new object has no 'tk' attribute. That's correct. It doesn't.
Apparently I have failed to call some necessary constructor. But which?
Maybe I'm close to having it right because if I create a grid attribute in
the class and pass the parameters to the frame grid method, the scrolled
listbox can be configured and displayed.
def grid(self,row=90,column=1,rowspan=5,columnspan=4,sticky=W) :
What am I doing wrong, or not doing right?
View this message in context: http://www.nabble.com/Creating-a-new-widget-class-tp18802754p18802754.html
Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.
More information about the Tkinter-discuss