Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Don't look back, the lemmings are gaining on you.


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

SubjectAuthor
o TkInter Scrolled Listbox class?Ulrich Goebel

1
Subject: TkInter Scrolled Listbox class?
From: Ulrich Goebel
Newsgroups: comp.lang.python
Date: Mon, 4 Nov 2024 15:32 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: ml@fam-goebel.de (Ulrich Goebel)
Newsgroups: comp.lang.python
Subject: TkInter Scrolled Listbox class?
Date: Mon, 4 Nov 2024 16:32:48 +0100
Lines: 43
Message-ID: <mailman.76.1730735763.4695.python-list@python.org>
References: <20241104163248.108d895a431837a246a22fe4@fam-goebel.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de 0H1PpB+d7VPwyVNm4uU1yw8pWbvDGzHKKQExvHvm0wrw==
Cancel-Lock: sha1:qk27YFUbMd6Aw298o1FHPQ6XyrM= sha256:7ByPSNdZbdJWqlEyiIajFA11ofLfwTEFQ2q3P6T5GjU=
Return-Path: <ml@fam-goebel.de>
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.009
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'def': 0.04; 'containing':
0.05; 'instances': 0.09; 'received:78': 0.09; 'subject:class':
0.09; 'possible?': 0.16; 'received:136.243': 0.16; 'received:your-
server.de': 0.16; 'problem': 0.16; "can't": 0.17; 'to:addr:python-
list': 0.20; 'skip:_ 10': 0.22; 'received:de': 0.23; 'seems':
0.26; 'configure': 0.26; 'bit': 0.27; 'received:136': 0.32; 'but':
0.32; 'really': 0.36; '...': 0.37; 'class': 0.37; 'two': 0.39;
'handle': 0.39; 'best': 0.61; 'pack': 0.64; 'packed': 0.69;
'skip:f 30': 0.71; 'skip:f 20': 0.75
X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu)
X-Authenticated-Sender: ml@fam-goebel.de
X-Virus-Scanned: Clear (ClamAV 0.103.10/27448/Mon Nov 4 10:33:38 2024)
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: <20241104163248.108d895a431837a246a22fe4@fam-goebel.de>
View all headers

Hi,

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:

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)
#
# configure these two
self.Listbox.config(yscrollcommand=self.Scrollbar.set)
self.Scrollbar.config(command=self.Listbox.yview)
#
# pack them in Frame
self.Listbox.pack(side=tk.LEFT, fill=tk.BOTH)
self.Scrollbar.pack(side=tk.RIGHT, fill=tk.BOTH)

That works, so instances of FrameScrolledListbox can be packed and the tk.Listbox itself is accessible via an attribute:

frmScrolledListbox = FrameScrolledListbox(main)
frmScrolledListbox.Listbox.config(...)

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(...)

Is that possible? The problem which I can't handle is to handle the Frame which seems to be needed to place the Scrollbar somewhere.

Best regards
Ulrich

--
Ulrich Goebel <ml@fam-goebel.de>

1

rocksolid light 0.9.8
clearnet tor