Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #196955

Re: TkInter Scrolled Listbox class?

From Cameron Simpson <cs@cskk.id.au>
Newsgroups comp.lang.python
Subject Re: TkInter Scrolled Listbox class?
Date 2024-11-05 08:21 +1100
Message-ID <mailman.77.1730755300.4695.python-list@python.org> (permalink)
References <20241104163248.108d895a431837a246a22fe4@fam-goebel.de> <Zyk62DZerPWhqFd1@cskk.homeip.net>

Show all headers | View raw


On 04Nov2024 16:32, Ulrich Goebel <ml@fam-goebel.de> wrote:
>I would like to build a class ScrolledListbox, which can be packed 
>somewhere in ttk.Frames. What I did is to build not really a scrolled 
>Listbox but a Frame containing a Listbox and a Scrollbar:

That's what I would build too.

>class FrameScrolledListbox(ttk.Frame):
>    def __init__(self, *args, **kwargs):
>        super().__init__(*args, **kwargs)
>        # build Listbox and Scrollbar
>        self.Listbox = tk.Listbox(self)
>        self.Scrollbar = ttk.Scrollbar(self)
[...]
>But it would be a bit nicer to get a class like
>
>class ScrolledListbox(tk.Listbox):
>    ...
>
>So it would be used that way:
>
>scrolledListbox = ScrolledListbox(main)
>scrolledListbox.config(...)

Probably you want to proxy various methods to the enclosed widgets.  
Possibly you want to do that with parameters in `__init__` also.

Example:

     class FrameScrolledListbox(ttk.Frame):
         def __init__(self, *frame_args, *, height=None, jump=None, **frame_kw):
             super().__init__(*frame_args, **frame_kw)
             self.Listbox = tk.Listbox(self, height=height)
             self.Scrollbar = ttk.Scrollbar(self, jump=jump)
             ........

         def config(self, *a, **kw):
             return self.Listbox.config(*a, **kw)

and so forth for the various listbox methods you want to proxy to the 
listbox itself. You could pass scroll specific methods to the scrollbar 
as well.

Cheers,
Cameron Simpson <cs@cskk.id.au>

Back to comp.lang.python | Previous | Next | Find similar


Thread

Re: TkInter Scrolled Listbox class? Cameron Simpson <cs@cskk.id.au> - 2024-11-05 08:21 +1100

csiph-web