[Tkinter-discuss] Creating a new widget class
peter.milliken at gmail.com
Tue Aug 5 23:42:24 CEST 2008
I won't answer the original question - sorry, no time to look at the code
But why roll your own? There is a PMW widget called ScrolledListBox that
probably does all that you require.
I would highly recommend the PMW distribution - it is exceptionally well
thought out and (IMO :-)) brilliantly executed. You can find it through any
of the Python resource pages or by Googling "Python PMW". It has been around
(and exceptionally stable) for a number of years now - it is at v1.2. I have
been using it for close to 8 years and it has only been up rev'd once in
It forms an excellent framework for creating your own composite widgets as
well. There is a bit of a learning curve to achieve that part (using
ScrolledListBox is easy) but once you get your head around the philosophy of
the package it is fantastically powerful.
So have a look at PMW - I can't recommend it enough :-)
On Mon, Aug 4, 2008 at 7:34 AM, vtcodger <donaldkenney at gmail.com> wrote:
> 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
> 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
> #Scrollbar version
> def __init__ (self, Tkobject, height=4, width=50) :
> #This code is executed whenever a new scrolled list object is
> #created (instantiated)
> self.f = Frame(Tkobject)
> s = Scrollbar(self.f,orient=VERTICAL)
> self.l = Listbox(self.f, height=height, width=width,
> yscrollcommand=s.set, exportselection=0)
> #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:
> Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tkinter-discuss