liveBook · Manning

Text box

As explained in Get Programming: Learn to code with Python

A text box is a graphical user-interface widget that allows a user to enter or edit text.

A text box is a graphical user-interface widget where users can enter or edit text. In tkinter, the Entry widget creates a single-line text field. Add it to a window by creating it and calling pack(). section 37.3 section 37.0

A text box becomes useful when another part of the program reads its contents:

  • Create an Entry widget and place it in the window. section 37.3
  • Read the entered value with textbox.get(), then convert or process it as needed. section 37.4
  • Connect a button to an event handler so the program responds after the user enters text. section 37.4

Entering a countdown value

A countdown program places an Entry beside instructions and a button. When the button is clicked, the handler reads the text box with int(textbox.get()), uses that number as the loop’s starting value, and displays the changing countdown in a label. section 37.4

Listing 37.2. Adding widgets to the window
import tkinter
window = tkinter.Tk()
window.geometry("800x200")
window.title("My first GUI")
window.configure(background="grey")

red = tkinter.Button(window, text="Red", bg="red")                 #1
red.pack()                                                         #2

yellow = tkinter.Button(window, text="Yellow", bg="yellow")
yellow.pack()

green = tkinter.Button(window, text="Green", bg="green")
green.pack()

textbox = tkinter.Entry(window)                                    #3
textbox.pack()                                                     #3

colorlabel = tkinter.Label(window, height="10", width="10")        #4
colorlabel.pack()                                                  #4

window.mainloop()

See a complete tkinter window containing three buttons, one Entry text box, and one label. section 37.3

How Get Programming: Learn to code with Python covers it

How deep it goes
Explains Entry creation, placement, retrieval, and event-driven use, but stops short of multi-line text handling.
Examples
Uses a countdown input, a complete widget window, and a phonebook exercise with name, phone, and email fields.
What it assumes
Assumes familiarity with text-based input and introduces visual windows, widgets, and interactions.
What you can do after
Builds tkinter interfaces that collect text, process entered values, and display results after button clicks.
How it connects
Connects text boxes with tkinter windows, widgets, buttons, event handlers, labels, loops, and user input.

Also explained in

Compare how 7 books explain text box →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Get Programming: Learn to code with Python. The section links point to the parts of the book it draws on.