Guido van Rossum | 1846882 | 1994-06-20 07:49:28 +0000 | [diff] [blame^] | 1 | # 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. |
| 10 | # Most methods calls are passed to the Text widget; the pack command |
| 11 | # is redirected to the Frame widget however. |
| 12 | |
| 13 | from Tkinter import * |
| 14 | |
| 15 | class ScrolledText(Pack, Place): |
| 16 | def __init__(self, master=None, cnf={}): |
| 17 | fcnf = {} |
| 18 | self.frame = Frame(master, {}) |
| 19 | if cnf.has_key(Pack): |
| 20 | self.frame.pack(cnf[Pack]) |
| 21 | del cnf[Pack] |
| 22 | self.vbar = Scrollbar(self.frame, {}) |
| 23 | self.vbar.pack({'side': 'right', 'fill': 'y'}) |
| 24 | cnf[Pack] = {'side': 'left', 'fill': 'both', |
| 25 | 'expand': 'yes'} |
| 26 | self.text = Text(self.frame, cnf) |
| 27 | self.text['yscrollcommand'] = (self.vbar, 'set') |
| 28 | self.vbar['command'] = (self.text, 'yview') |
| 29 | self.insert = self.text.insert |
| 30 | # XXX should do all Text methods... |
| 31 | self.pack = self.frame.pack |
| 32 | self.forget = self.frame.forget |
| 33 | self.tk = master.tk |
| 34 | def __str__(self): |
| 35 | return str(self.frame) |