[Tkinter-discuss] Binding a List to a ScrollBar

Rob Ward rl.ward at bigpond.com
Thu Jan 16 07:06:26 CET 2014


Hi Folks,
Sorry to be back so soon but I have another challenge.  I wanted to choose some colours for my program and came across a program that claimed to list the colours in a nifty little Python program.  Cute I thought, I must try that. Quite a few hours later I am stumped.  Here is the code with only the first 26 colours as data -

from tkinter import *

COLORS  =['snow', 'ghost white', 'white smoke', 'gainsboro', 'floral white', 'old lace',
    'linen', 'antique white', 'papaya whip', 'blanched almond', 'bisque', 'peach puff',
    'navajo white', 'lemon chiffon', 'mint cream', 'azure', 'alice blue', 'lavender',
    'lavender blush', 'misty rose', 'dark slate gray', 'dim gray', 'slate gray',
    'light slate gray', 'gray', 'light grey']

root = Tk()
scrollbar = Scrollbar(root)
scrollbar.pack( side = RIGHT, fill=Y )

mylist = Listbox(root, yscrollcommand = scrollbar.set )
for c in COLORS:
    e = Label(mylist, text = c, background = c)
    mylist.insert(END,e )
    e.pack(fill=X)#Problem line????

mylist.pack( side = LEFT, fill = BOTH )
scrollbar.config( command = mylist.yview )

mainloop()

As you can see I have an interesting line shown as a "Problem line????". If this line is out I get a list of pairs of number showing the default 10 lines and  the list of numbers is "scrollable".  However if the line is in as shown above, I get a list 26 lines long, with the lovely colours nicely shown.  If I drag the list to a shorter size, the scroll bar appears but its movement does not link with the list.  It goes up an down nicely but the list stays still.  This is rather inconvenient when trying to view the complete list of colours, which is 479 high!

Thanks in anticipation of anyone being able to help me, it will be very much appreciated.

Cheers, Rob

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20140116/230dd50b/attachment.html>


More information about the Tkinter-discuss mailing list