Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Do something unusual today. Pay a bill.


comp / comp.lang.python / Re: TkInter Scrolled Listbox class?

SubjectAuthor
o Re: TkInter Scrolled Listbox class?Cameron Simpson

1
Subject: Re: TkInter Scrolled Listbox class?
From: Cameron Simpson
Newsgroups: comp.lang.python
Date: Mon, 4 Nov 2024 21:21 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: cs@cskk.id.au (Cameron Simpson)
Newsgroups: comp.lang.python
Subject: Re: TkInter Scrolled Listbox class?
Date: Tue, 5 Nov 2024 08:21:28 +1100
Lines: 45
Message-ID: <mailman.77.1730755300.4695.python-list@python.org>
References: <20241104163248.108d895a431837a246a22fe4@fam-goebel.de>
<Zyk62DZerPWhqFd1@cskk.homeip.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii; format=flowed
X-Trace: news.uni-berlin.de aopdjbeVWSIpxd7ETvXexAsTnITq5K9c5AkN+cCZR85A==
Cancel-Lock: sha1:WHSf82r8CSSxHFhBJzckmDDUjtU= sha256:se0qXPrrv40mr6BVXYxblww78N3uTNXWTTpmhjeR1E4=
Return-Path: <cameron@cskk.id.au>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'def': 0.04; 'containing':
0.05; 'cc:addr:python-list': 0.09; 'example:': 0.09; 'scroll':
0.09; 'subject:class': 0.09; 'cheers,': 0.11; 'cc:no real
name:2**0': 0.14; 'also.': 0.16; 'cameron': 0.16; 'from:addr:cs':
0.16; 'from:addr:cskk.id.au': 0.16; 'from:name:cameron simpson':
0.16; 'message-id:@cskk.homeip.net': 0.16; 'received:13.237':
0.16; 'received:13.237.201': 0.16; 'received:13.237.201.189':
0.16; 'received:cskk.id.au': 0.16; 'received:id.au': 0.16;
'received:mail.cskk.id.au': 0.16; 'simpson': 0.16; 'skip:> 10':
0.16; 'skip:> 20': 0.16; 'widgets.': 0.16; 'wrote:': 0.16;
'probably': 0.17; 'cc:addr:python.org': 0.20; 'skip:_ 10': 0.22;
'cc:2**0': 0.25; 'bit': 0.27; 'header:User-Agent:1': 0.30; 'but':
0.32; 'header:In-Reply-To:1': 0.34; 'received:au': 0.35; 'really':
0.36; 'possibly': 0.36; '...': 0.37; 'could': 0.37; 'class': 0.37;
"that's": 0.39; 'methods': 0.39; 'want': 0.40; 'skip:h 10': 0.61;
'pass': 0.64; 'received:13': 0.64; 'received:userid': 0.66;
'enclosed': 0.69; 'packed': 0.69; 'too.': 0.70; 'skip:f 30': 0.71;
'itself.': 0.84
Mail-Followup-To: Ulrich Goebel <ml@fam-goebel.de>, python-list@python.org
Content-Disposition: inline
In-Reply-To: <20241104163248.108d895a431837a246a22fe4@fam-goebel.de>
User-Agent: Mutt/2.2.13 (2024-03-09)
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <Zyk62DZerPWhqFd1@cskk.homeip.net>
X-Mailman-Original-References: <20241104163248.108d895a431837a246a22fe4@fam-goebel.de>
View all headers

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>

1

rocksolid light 0.9.8
clearnet tor