ยปCore Development>Code coverage>Lib/tkinter/scrolledtext.py

Python code coverage for Lib/tkinter/scrolledtext.py

#countcontent
1n/a"""A ScrolledText widget feels like a text widget but also has a
2n/avertical scroll bar on its right. (Later, options may be added to
3n/aadd a horizontal bar as well, to make the bars disappear
4n/aautomatically when not needed, to move them to the other side of the
5n/awindow, etc.)
6n/a
7n/aConfiguration options are passed to the Text widget.
8n/aA Frame widget is inserted between the master and the text, to hold
9n/athe Scrollbar widget.
10n/aMost methods calls are inherited from the Text widget; Pack, Grid and
11n/aPlace methods are redirected to the Frame widget however.
12n/a"""
13n/a
14n/a__all__ = ['ScrolledText']
15n/a
16n/afrom tkinter import Frame, Text, Scrollbar, Pack, Grid, Place
17n/afrom tkinter.constants import RIGHT, LEFT, Y, BOTH
18n/a
19n/aclass ScrolledText(Text):
20n/a def __init__(self, master=None, **kw):
21n/a self.frame = Frame(master)
22n/a self.vbar = Scrollbar(self.frame)
23n/a self.vbar.pack(side=RIGHT, fill=Y)
24n/a
25n/a kw.update({'yscrollcommand': self.vbar.set})
26n/a Text.__init__(self, self.frame, **kw)
27n/a self.pack(side=LEFT, fill=BOTH, expand=True)
28n/a self.vbar['command'] = self.yview
29n/a
30n/a # Copy geometry methods of self.frame without overriding Text
31n/a # methods -- hack!
32n/a text_meths = vars(Text).keys()
33n/a methods = vars(Pack).keys() | vars(Grid).keys() | vars(Place).keys()
34n/a methods = methods.difference(text_meths)
35n/a
36n/a for m in methods:
37n/a if m[0] != '_' and m != 'config' and m != 'configure':
38n/a setattr(self, m, getattr(self.frame, m))
39n/a
40n/a def __str__(self):
41n/a return str(self.frame)
42n/a
43n/a
44n/adef example():
45n/a from tkinter.constants import END
46n/a
47n/a stext = ScrolledText(bg='white', height=10)
48n/a stext.insert(END, __doc__)
49n/a stext.pack(fill=BOTH, side=LEFT, expand=True)
50n/a stext.focus_set()
51n/a stext.mainloop()
52n/a
53n/aif __name__ == "__main__":
54n/a example()