Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_listboxfullscroll.py
- from Tkinter import *
- def yview(*args):
- """ scroll both listboxes together """
- if len(args) is 1: args = "scroll", args, "units"
- select1.yview(*args)
- select2.yview(*args)
- root = Tk()
- keyU=38
- keyD=40
- keyL=37
- keyR=39
- root.hasFocus = None
- frame = Frame(root)
- frame.pack()
- scroll = Scrollbar(frame, orient=VERTICAL, command=yview)
- select1 = Listbox(frame, height=30, width=40, selectmode=SINGLE, selectbackground='purple')
- # + exportselection=False
- select1.config(yscrollcommand=scroll.set)
- select1.pack(side=LEFT)
- select2 = Listbox(frame, height=30, width=160, selectmode=SINGLE, selectbackground='purple') # selectmode=MULTIPLE
- select2.config(yscrollcommand=scroll.set)
- scroll.pack(side=RIGHT, fill=Y)
- select2.pack(side=RIGHT)
- def OnFocus1(e):
- root.hasFocus = 'Column A'
- OnSelect(e)
- def OnFocus2(e):
- root.hasFocus = 'Column B'
- OnSelect(e)
- def OnSelect(e):
- w = e.widget
- cbgSelect()
- print root.hasFocus
- for i in w.curselection():
- print 'You selected: %s' % (w.get(i)) ### ZZZ generic for multi-select option
- select1.itemconfigure(i, fg='white', bg='purple')
- select2.itemconfigure(i, fg='white', bg='purple')
- print
- frame.focus_set()
- def OnMouseWheel(event):
- e = -25
- if event.delta < 1: e = 25
- yview(e)
- return 'break'
- def OnKeyPressed(event):
- e=0
- if event.keycode is keyU: e = -1
- elif event.keycode is keyD: e = 1
- yview(e)
- return 'break'
- select1.bind('<FocusIn>', OnFocus1)
- select2.bind('<FocusIn>', OnFocus2)
- frame.bind_all('<MouseWheel>', OnMouseWheel)
- # frame.bind_all("<Button-1>", OnMouseL) ### replaced with OnFocus
- frame.bind_all('<KeyPress>', OnKeyPressed)
- # frame.bind_all('<<ListboxSelect>>', OnSelect)
- def setSelect() :
- select1.delete(0,END)
- select2.delete(0,END)
- for i in range(100):
- select1.insert('end','%s' % i)
- select2.insert('end','%s' % i)
- cbgSelect()
- def cbgSelect() :
- for i in range(0, 100):
- cbg = '#FFFFFF'
- if i % 2: cbg = '#CCCCFF'
- select1.itemconfigure(i, fg='#000000', bg=cbg)
- select2.itemconfigure(i, fg='#000000', bg=cbg)
- setSelect()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement