FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merged revisions 68006 via svnmerge from · python/cpython@e354d78 · GitHub

Repository navigation

Commit e354d78

Browse files
committed
Merged revisions 68006 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r68006 | martin.v.loewis | 2008-12-29 16:51:01 +0100 (Mo, 29 Dez 2008) | 2 lines Issue #3248: Allow placing ScrolledText in a PanedWindow. ........
1 parent 7560d7a commit e354d78

2 files changed

Lines changed: 44 additions & 32 deletions

File tree

‎Lib/tkinter/scrolledtext.py‎

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,52 @@
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 inherited from the Text widget; Pack methods
11-
# are redirected to the Frame widget however.
12-
13-
from tkinter import *
14-
from tkinter import _cnfmerge
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 inherited from the Text widget; Pack, Grid and
11+
Place methods are redirected to the Frame widget however.
12+
"""
13+
14+
__all__ = ['ScrolledText']
15+
16+
from tkinter import Frame, Text, Scrollbar, Pack, Grid, Place
17+
from tkinter.constants import RIGHT, LEFT, Y, BOTH
1518

1619
class ScrolledText(Text):
17-
def __init__(self, master=None, cnf=None, **kw):
18-
if cnf is None:
19-
cnf = {}
20-
if kw:
21-
cnf = _cnfmerge((cnf, kw))
22-
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-
26-
self.frame = Frame(master, **fcnf)
27-
self.vbar = Scrollbar(self.frame, name='vbar')
20+
def __init__(self, master=None, **kw):
21+
self.frame = Frame(master)
22+
self.vbar = Scrollbar(self.frame)
2823
self.vbar.pack(side=RIGHT, fill=Y)
29-
cnf['name'] = 'text'
30-
Text.__init__(self, self.frame, **cnf)
31-
self.pack(side=LEFT, fill=BOTH, expand=1)
32-
self['yscrollcommand'] = self.vbar.set
24+
25+
kw.update({'yscrollcommand': self.vbar.set})
26+
Text.__init__(self, self.frame, **kw)
27+
self.pack(side=LEFT, fill=BOTH, expand=True)
3328
self.vbar['command'] = self.yview
3429

3530
# Copy geometry methods of self.frame -- hack!
36-
methods = Pack.__dict__.keys()
37-
methods = methods + Grid.__dict__.keys()
38-
methods = methods + Place.__dict__.keys()
31+
methods = vars(Pack).keys() + vars(Grid).keys() + vars(Place).keys()
3932

4033
for m in methods:
4134
if m[0] != '_' and m != 'config' and m != 'configure':
4235
setattr(self, m, getattr(self.frame, m))
36+
37+
def __str__(self):
38+
return str(self.frame)
39+
40+
41+
def example():
42+
import __main__
43+
from tkinter.constants import END
44+
45+
stext = ScrolledText(bg='white', height=10)
46+
stext.insert(END, __main__.__doc__)
47+
stext.pack(fill=BOTH, side=LEFT, expand=True)
48+
stext.focus_set()
49+
stext.mainloop()
50+
51+
if __name__ == "__main__":
52+
example()

‎Misc/NEWS‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ Core and Builtins
6464
Library
6565
-------
6666

67+
- Issue #3248: Allow placing ScrolledText in a PanedWindow.
68+
6769
- Issue #4444: Allow assertRaises() to be used as a context handler, so that
6870
the code under test can be written inline if more practical.
6971

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL