December 2017
Beginner
412 pages
10h 8m
English
To end this chapter, we will look at a few more commonly used widgets.
The Entry widget that we have been using since the start of this chapter allows for only a single line of text. If we want multiple lines of text, we use the Text widget instead, as shown here:
| | import tkinter |
| | |
| | def cross(text): |
| | text.insert(tkinter.INSERT, 'X') |
| | |
| | window = tkinter.Tk() |
| | frame = tkinter.Frame(window) |
| | frame.pack() |
| | |
| | text = tkinter.Text(frame, height=3, width=10) |
| | text.pack() |
| | |
| | button = tkinter.Button(frame, text='Add', command=lambda: cross(text)) |
| | button.pack() |
| | |
| | window.mainloop() |
Here is the resulting GUI:
Text provides a much richer set of methods than the other widgets we have seen so far. ...
Read now
Unlock full access