Can a Tkinter Scrollbar scroll 2 widgets at the same time?
Steve Holden
sholden at holdenweb.com
Mon Feb 12 16:49:46 EST 2001
"SNYDER, BARRON F. (AIT)" <bs1535 at sbc.com> wrote in message
news:mailman.982012694.3832.python-list at python.org...
>
> Since Tkinter doesn't have a table widget, I'm using a ScrolledListBox and
a
> ScrolledFrame (to hold the column headings as Buttons). I would like the
> scrollbar from the ScrolledListBox to scroll both ScrolledListBox and
> ScrolledFrame at the same time. Is this possible?
>
> If not, can a separate Scrollbar scroll more than one widget (can I
scroll,
> say, 2 listboxes with one scrollbar?)?
>
> Thanks,
> Barron
>
Traditionally you do this by registering the set() method of the scroll bar
as the yscrollcommand of each of the listboxes, and registering a callback
for the scroll bar which adjusts the positions of each listbox.
Here's an extract from the __init__() method of a mail searchwindow, which
shows you how this works in practice:
self.msgScrollBar.config(command=self.scrollMsg)
self.msgDateList = Listbox(self.msgFrame, borderwidth=1, bg='white',
yscrollcommand=self.msgScrollBar.set,
exportselection=0)
self.msgDateList.bind("<Double-Button-1>", self.showMessage)
self.msgSenderList = Listbox(self.msgFrame, borderwidth=1,
bg='white',
yscrollcommand=self.msgScrollBar.set,
exportselection=0)
self.msgSubjectList = Listbox(self.msgFrame, borderwidth=1,
bg='white',
yscrollcommand=self.msgScrollBar.set,
exportselection=0)
And here's the code of the scrollMsg callback from msgScrollBar events:
def scrollMsg(self, *args):
apply(self.msgDateList.yview, args)
apply(self.msgSenderList.yview, args)
apply(self.msgSubjectList.yview, args)
This does have limitations, though, since any changes to the scrolling lists
made by keyboard aren't reflected in the others.
regards
Steve
PS: Can anyone explain how I might implement a columnar scrolling list,
allowing different text elements to align vertically inside each row of a
scrolling list -- without using a fixed-pitch font? This would solve an
interface problem for me.
More information about the Python-list
mailing list