return self.text.get('1.0', END+'-1c') # first through last
if name == 'main':
root = Tk()
if len(sys.argv) > 1:
st = ScrolledText(file=sys.argv[1]) # filename on cmdline
else:
st = ScrolledText(text='Words\ngo here') # or not: two lines
def show(event):
print(repr(st.gettext())) # show as raw string
root.bind('
root.mainloop()
Like the ScrolledList in Example 9-9, the ScrolledText object in this file is designed
to be a reusable component which we’ll also put to work in later examples, but it can
also be run standalone to display text file contents. Also like the last section, this script
is careful to pack the scroll bar first so that it is cut out of the display last as the window
shrinks and arranges for the embedded Text object to expand in both directions as the
window grows. When run with a filename argument, this script makes the window
shown in Figure 9-17; it embeds a Text widget on the left and a cross-linked Scroll
bar on the right.
Figure 9-17. scrolledtext in action
Just for fun, I populated the text file displayed in the window with the following code
and command lines (and not just because I used to live near an infamous hotel in
Colorado):
C:\...\PP4E\Gui\Tour> type makefile.py
f = open('jack.txt', 'w')
Text | 529