Created
June 25, 2013 21:35
-
-
Save mikofski/5862657 to your computer and use it in GitHub Desktop.
scroll 2 listboxes in paned windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
from Tkinter import * | |
from ttk import * | |
import calendar | |
root = Tk() | |
master = Frame(root) | |
master.pack(expand=YES, fill=BOTH) | |
panels = PanedWindow(master, orient=HORIZONTAL) | |
panels.pack(expand=YES, fill=BOTH) | |
panel1 = Frame(panels) | |
panel1.pack(expand=YES, fill=BOTH) | |
list1 = Listbox(panel1) | |
list1.pack(side=LEFT, expand=YES, fill=BOTH) | |
for m in calendar.month_name: | |
list1.insert(END, m) | |
for d in calendar.day_name: | |
list1.insert(END, d) | |
panel2 = Frame(panels) | |
panel2.pack(expand=YES, fill=BOTH) | |
list2 = Listbox(panel2) | |
list2.pack(side=LEFT, expand=YES, fill=BOTH) | |
for m in calendar.month_name: | |
list2.insert(END, m) | |
for d in calendar.day_name: | |
list2.insert(END, d) | |
scroll = Scrollbar(panel2, orient=VERTICAL) | |
scroll.pack(side=RIGHT, fill=Y) | |
list1.config(yscrollcommand=scroll.set) | |
list2.config(yscrollcommand=scroll.set) | |
scroll.config(command=lambda *args: onScroll([list1, list2], *args)) | |
Label(master, text='scrolled lists').pack(side=LEFT, fill=BOTH) | |
Button(master, text='quit', command=master.quit).pack(side=RIGHT, fill=BOTH) | |
panels.add(panel1) | |
panels.add(panel2) | |
def onScroll(lists, *args): | |
for l in lists: | |
l.yview(*args) | |
if __name__ == '__main__': | |
master.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment