blob: 35767e669b9844113ec6e86fbb2fd958ba3d2723 [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
Georg Brandl14fc4272008-05-17 18:39:55 +000013from tkinter import *
14from tkinter import _cnfmerge
Guido van Rossum18468821994-06-20 07:49:28 +000015
Guido van Rossum460b6bb1994-07-06 21:54:39 +000016class ScrolledText(Text):
Fred Draked038ca82000-10-23 18:31:14 +000017 def __init__(self, master=None, cnf=None, **kw):
18 if cnf is None:
19 cnf = {}
20 if kw:
21 cnf = _cnfmerge((cnf, kw))
Guilherme Polob212b752008-09-04 11:21:31 +000022 fcnf = {k:v for k,v in cnf.items() if isinstance(k,type) or k=='name'}
23 for k in fcnf.keys():
24 del cnf[k]
25
Raymond Hettingerff41c482003-04-06 09:01:11 +000026 self.frame = Frame(master, **fcnf)
Fred Draked038ca82000-10-23 18:31:14 +000027 self.vbar = Scrollbar(self.frame, name='vbar')
28 self.vbar.pack(side=RIGHT, fill=Y)
29 cnf['name'] = 'text'
Raymond Hettingerff41c482003-04-06 09:01:11 +000030 Text.__init__(self, self.frame, **cnf)
Fred Draked038ca82000-10-23 18:31:14 +000031 self.pack(side=LEFT, fill=BOTH, expand=1)
32 self['yscrollcommand'] = self.vbar.set
33 self.vbar['command'] = self.yview
Guido van Rossum460b6bb1994-07-06 21:54:39 +000034
Guido van Rossum61d36372001-12-10 16:42:43 +000035 # Copy geometry methods of self.frame -- hack!
Guido van Rossum19909432001-12-12 12:47:57 +000036 methods = Pack.__dict__.keys()
37 methods = methods + Grid.__dict__.keys()
38 methods = methods + Place.__dict__.keys()
Guido van Rossum61d36372001-12-10 16:42:43 +000039
40 for m in methods:
Fred Draked038ca82000-10-23 18:31:14 +000041 if m[0] != '_' and m != 'config' and m != 'configure':
42 setattr(self, m, getattr(self.frame, m))