Page 304 -
P. 304
guis and data
Entry fields are used for single lines Remove text with the delete()
of text. method.
Text fields are used to handle multi- Entry fields are indexed with a
line text. number starting at 0.
Read the contents of fields with the Text fields are indexed with a string,
get() method. starting at “1.0”.
Add text using the insert() method.
Q: Is it possible to put more than one line of text into an Q: Why can’t we just assign a value to an Entry box using
Entry box widget? the assignment operator (=)? Why do we have to use the
insert() method?
A: Yes, you probably could, but if you need to do this, you are
much better off using a Text box, because they are designed to A: The Entry box is a widget object, not a Python variable,
handle more than one line of text. so using the assignment operator does not make sense here.
Q: I notice that we are calling the pack() method as part of When working with objects, you need to use the application
programming interface (API) provided by and included with the
the label creation code, whereas before we assigned the label object, which in this case is the insert() method.
to a variable then called pack() on the new variable. Which Q:
packing technique should I use and does it really matter? Why do the rows in a Text box start counting from one
as opposed to zero (like everything else in Python)?
A: No, it does not really matter which technique you use to call
pack(). If it makes sense to pack your widgets as they are A:Beats the hell out of us. No idea.
created, include the call to pack() as part of the creation code. Q:
If it doesn’t make sense, assign the widget to a variable and do So, just to be clear, Who is on first?
your packing whenever you need to. If you look at other examples
of tkinter code on the Web, you’ll see that other programmers use A: No. Who is on second. Python is on first.
both techniques.
you are here 4 269