blob: 2683696f72fecd4395d222d651fca1078015ca5e [file] [log] [blame]
Guido van Rossum18468821994-06-20 07:49:28 +00001# A ScrolledText widget feels like a text 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 Text widget.
8# A Frame widget is inserted between the master and the text, to hold
9# the Scrollbar widget.
Guido van Rossum460b6bb1994-07-06 21:54:39 +000010# Most methods calls are inherited from the Text widget; Pack methods
11# are redirected to the Frame widget however.
Guido van Rossum18468821994-06-20 07:49:28 +000012
13from Tkinter import *
Guido van Rossum460b6bb1994-07-06 21:54:39 +000014from Tkinter import _cnfmerge
Guido van Rossum18468821994-06-20 07:49:28 +000015
Guido van Rossum460b6bb1994-07-06 21:54:39 +000016class ScrolledText(Text):
Guido van Rossum18468821994-06-20 07:49:28 +000017 def __init__(self, master=None, cnf={}):
Guido van Rossum460b6bb1994-07-06 21:54:39 +000018 cnf = _cnfmerge(cnf)
Guido van Rossum18468821994-06-20 07:49:28 +000019 fcnf = {}
Guido van Rossum460b6bb1994-07-06 21:54:39 +000020 for k in cnf.keys():
21 if type(k) == ClassType:
22 fcnf[k] = cnf[k]
23 del cnf[k]
24 self.frame = Frame(master, fcnf)
25 self.vbar = Scrollbar(self.frame, {
26 Pack: {'side': 'right', 'fill': 'y'}})
Guido van Rossum51792361994-07-06 21:15:27 +000027 cnf[Pack] = {'side': 'left', 'fill': 'both', 'expand': 'yes'}
Guido van Rossum460b6bb1994-07-06 21:54:39 +000028 Text.__init__(self, self.frame, cnf)
29 self['yscrollcommand'] = (self.vbar, 'set')
30 self.vbar['command'] = (self, 'yview')
31
32 # Copy Pack methods of self.frame -- hack!
33 for m in Pack.__dict__.keys():
34 if m[0] != '_' and m != 'config':
35 setattr(self, m, getattr(self.frame, m))