[Tkinter-discuss] Creating a new widget class

Peter Milliken 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
that time.

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 :-)

Peter

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
> too
> hard.
>
> 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.config(command=self.l.yview)
>    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) :
>
>
> self.f.grid(row=row,column=column,rowspan=rowspan,columnspan=columnspan,sticky=sticky)
>
> 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.
>
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20080806/a446f85a/attachment.htm>


More information about the Tkinter-discuss mailing list