Entry

Two widgets let users enter text. The simplest one is Entry, which allows for a single line of text. If we associate a StringVar with the Entry, then window window

Figure 14.7: Structure of a three-label GUI

whenever a user types anything into that Entry, the StringVar's value will automatically be updated to the contents of the Entry. If that same String-Var is also bound to a label, then the label will display whatever is currently in the Entry without us doing any extra work. The following code shows how to set this up, and we can see what the GUI looks like in Figure 14.8, on the following page:

Download gui/entry.py

from Tkinter import *

frame = Frame(window) frame.pack()

var = StringVar()

label = Label(frame, textvariable=var) label.pack()

entry = Entry(frame, textvariable=var) entry.pack()

window.mainloop()

Was this article helpful?

0 0

Post a comment