[Tkinter-discuss] Creating a new widget class
peter.milliken at gmail.com
Thu Aug 7 06:05:36 CEST 2008
Well, here are some clues - the "multiple" inheritance doesn't seem to work
the way the manual *implies* it should i.e. multiple inheritance is
described as searching for methods in the first inheritance and then all
it's ancestors, then onto the next and all its ancestors and so on.
To get an "insert" (Listbox) method on your class you need to invoke the
__init__ method on the super classes (sub-classes should always invoke the
initialisation of their super class anyway - so that is something your class
definition is definitely missing!) i.e.
If you do just this, then ScrolledList has the Listbox attributes (and none
of the others). If you then add initialisation of Scrollbar then you have
And viola! ScrolledList now has the methods of Scrollbar - and "lost" the
methods of Listbox.
So without being any kind of expert on Tk objects with inheritance etc it
looks very much as though you have attempted too simplistic an approach to
creating what amounts to a "composite" object.
I would suggest that you pick one of your 3 objects to do the real
inheritance - and then create actual methods on ScrolledList that
"duplicate" the methods of the other object methods. That is the only way I
can see you get this working at the moment.
Hope this helps
On Wed, Aug 6, 2008 at 6:23 PM, vtcodger <donaldkenney at gmail.com> wrote:
> Ron -- Thanks, I thought I was doing about what you describe, but
> not as the tk attribute for the class objects is not getting set up. I'm a
> bit hazy on what the tk attribute does (other than making things work) and
> can't find much about it via Google. I'll go back and subclass from frame
> rather than trying to multiply inherit from Frame, List, and Scrollbar.
> Peter -- Thanks also. I was aware of the PMW scrolledlist. And it works
> fine. But I don't want to use any components that are not part of the
> standard Python distribution. Should have mentioned that, but the post was
> getting overlong.
> As a practical matter, I discovered after I posted, that I can access my
> frame, list (and probably scrollbar as well) methods from the main program
> via their objects. That is to say that the way I did it, a scrolled list
> object sl doesn't have a directly usable grid or insert method, but
> sl.f.grid(... or sl.l.insert seem to work fine.
> What bothers me, isn't that I can't get things to work. It's that I
> don't understand what is going on.
> 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