blob: 8bb5738f1d23b6099c1c9f16f92ea493119067cf [file] [log] [blame]
Guido van Rossumd2112201995-03-02 14:05:29 +00001# A ScrolledList widget feels like a list widget but also has a
2# vertical scroll bar on its right. (Later, options may be added to
3# add a horizontal bar as well, to make the bars disappear
4# automatically when not needed, to move them to the other side of the
5# window, etc.)
6#
7# Configuration options are passed to the List widget.
8# A Frame widget is inserted between the master and the list, to hold
9# the Scrollbar widget.
10# Most methods calls are inherited from the List widget; Pack methods
11# are redirected to the Frame widget however.
12
13from Tkinter import *
14from Tkinter import _cnfmerge
15
16class ScrolledListbox(Listbox):
Martin v. Löwis23b44a32003-10-24 20:09:23 +000017 def __init__(self, master=None, cnf={}):
18 cnf = _cnfmerge(cnf)
19 fcnf = {}
20 vcnf = {'name': 'vbar',
21 Pack: {'side': 'right', 'fill': 'y'},}
22 for k in cnf.keys():
23 if type(k) == ClassType or k == 'name':
24 fcnf[k] = cnf[k]
25 del cnf[k]
26 self.frame = Frame(master, fcnf)
27 self.vbar = Scrollbar(self.frame, vcnf)
28 cnf[Pack] = {'side': 'left', 'fill': 'both', 'expand': 'yes'}
29 cnf['name'] = 'list'
30 Listbox.__init__(self, self.frame, cnf)
31 self['yscrollcommand'] = (self.vbar, 'set')
32 self.vbar['command'] = (self, 'yview')
Guido van Rossumd2112201995-03-02 14:05:29 +000033
Martin v. Löwis23b44a32003-10-24 20:09:23 +000034 # Copy Pack methods of self.frame -- hack!
35 for m in Pack.__dict__.keys():
36 if m[0] != '_' and m != 'config':
37 setattr(self, m, getattr(self.frame, m))