The Text Widget
Class Text implements a powerful multiline text editor, which can display images and embedded widgets as well as text in one or more fonts and colors. An instance t of Text supports many ways to refer to specific points in t’s contents. t supplies methods and configuration options, which allows fine-grained control of operations, content, and rendering. This section covers a large, frequently used subset of this vast functionality. In some very simple cases, you can get by with just three Text-specific idioms:
t.delete('1.0', END) # clear the widget's contents t.insert(END, astring) # append astring to the widget's contents somestring = t.get('1.0', END) # get the widget's contents as a string
END is an index on any Text instance t, indicating the end of t’s text. '1.0' is also an index, indicating the start of t’s text (first line, first column). For more about indices, see Indices.
The ScrolledText Module
The ScrolledText module of Python’s standard library supplies a class named ScrolledText. To construct a ScrolledText instance, call ScrolledText.ScrolledText in exactly the same way you would call Tkinter.Text. A ScrolledText instance s is exactly the same as a Text instance, except that s automatically provides a scrollbar for the Text instance it wraps.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access