[Tkinter-discuss] Problems with a scrollbar on a listbox

Michael O'Donnell michael.odonnell at uam.es
Tue Aug 19 07:59:22 CEST 2008


  To link a scroller to a widget, you need to link in both directions:
not only setting the yscrollcommand of the ListBox but also:

        self.urlscrollbar.config(command=self. diclistBox.yview)

Example below:

from Tkinter import *

class ScrolledListBox(Frame):

    def __init__(self, master, items=[], width=24, height=20,
bgcol="white", **keywords):
        Frame.__init__(self, master)

        # Scrollbars
        scrollbar = Scrollbar(self, orient=VERTICAL)

        # Create the listbox
        self.table=Listbox(self, yscrollcommand=scrollbar.set, **keywords)
        self.table.config(bg = bgcol, width=width, height=height)
        scrollbar.pack(side=RIGHT, fill=Y)
        self.table.pack(side=LEFT, fill=BOTH, expand=1)

        # insert the items
        for item in items:
            self.table.insert(END, item)

On Tue, Aug 19, 2008 at 7:30 AM, Alexnb <alexnbryan at gmail.com> wrote:
> So I have a listBox and a scrollbar, both in the same frame. I have them set
> up just as I do my text widgets, and they work just as they should. Here is
> how I have it:
> self.urlscrollbar = Scrollbar(self.insidebuffer1)
>        self.urlscrollbar.pack(side=RIGHT, fill=Y)
> self.diclistBox = Listbox(self.insidebuffer1, selectmode=MULTIPLE,
>                                  yscrollcommand=self.urlscrollbar.set)
>        self.diclistBox.pack(side=TOP, anchor=N, fill=BOTH)
> I am on a mac if it matters. But what happens is they show up, and when the
> list in the listbox is big enough, the bar turns blue like it is able to
> scroll; but it doesn't function. Any ideas? Did I leave something out?
> --
> View this message in context: http://www.nabble.com/Problems-with-a-scrollbar-on-a-listbox-tp19044535p19044535.html
> Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss

More information about the Tkinter-discuss mailing list