Next / Previous / Contents / Shipman's homepage

3. Using a ScrolledList widget in your Tkinter application

Here is how you call the constructor for a ScrolledList widget.

s = ScrolledList(master, width=W, height=H, vscroll=VS,
                   hscroll=HS, callback=c)
s

The constructor returns a new ScrolledList widget that has not been registered. Be sure to register it with the .grid() method or it will not appear in your application.

master

The parent Frame widget in which the new ScrolledList widget is to be mastered.

width=W

The width of the Listbox in characters. The default value is defined in Section 5.3.1, “DEFAULT_WIDTH: Default list width”.

height=H

The height of the Listbox in lines. The default value is defined in Section 5.3.2, “DEFAULT_HEIGHT: Default list height”.

vscroll=VS

By default, you will get a vertical scrollbar. If you don't want one, use “vscroll=0”.

hscroll=HS

By default, you will not get a horizontal scrollbar. If you do want one, use “hscroll=1”.

callback=c

If you want your application to react whenever a user clicks on a line in the Listbox, use this keyword argument to supply a function c, and that function will be called whenever the user clicks on a line. You should define your function like this:

def c(lineNo):
    ...

where the lineNo argument will be the index (starting at 0) of the line on which the user clicked. For example, if the user clicks on the third line, the ScrolledList widget will call your procedure with an argument 2.