Entry widget lets the user enter a single line of text that has only one font type. If more lines are required, you should use Tkinter
Entry widget could also be used to display the single-line text.
Tkinter Entry Example
This example code creates a GUI that the user could enter the country and city names, then it displays the entered information after
Get Result button is clicked.
entryLand = tk.Entry(app, width=20, textvariable=landString)
It creates one Tkinter
Entry widget instance whose width is 20 character units. It could only display 20 characters in the entry box, therefore, you need to use arrow keys to display the rest of the line if the text line has more than 20 characters.
The text of the entry widget is assigned to a Tkinter string variable
landString. You could get the text with
landString.get() method, and set the text with
landString.set() method. The text in the entry box updates automatically if
set() method is used.
get() method of
StringVar, you could also use
get() method of
Entry widget object to retrieve the string in
Tkinter Entry Default Text
We have two ways to set the
Entry default text,
Set() Method to Set the Default Text of Tkinter
As indicated in the above example, you could use
set() method of
StringVar to set the default text of Tkinter
It will set the default text as
Insert() Method to Set Tkinter
Entry Default Text
insert(index, string) method inserts the text
string at the given
index position. And if
END, it appends the text to the
It sets the default text to be
index is larger than the length of existing string in the widget, it is equal to