In this video we’ll learn about the Entry Widget for Tkinter and Python.

The Entry Widget is a text box that allows users to type text into your GUI app.

We’ll learn how to create an entry widget, and how to retrieve the text from it and do things with it!

We’ll also learn how to delete text from the entry box, and add text programatically.

Python Code: entry.py
(Github Code)

from tkinter import *

root = Tk()
root.title("Entry Widget - Intro To Tkinter")
root.iconbitmap('images/tkinter.ico')
root.geometry('500x350')

def insert():
	# Insert "John" into the entry box
	my_entry.insert(2, "John")


def answer():
	# Delete Hidden Label
	hidden_label.config(text="")
	# Logic to make sure they typed in a name
	if my_entry.get():
		# Output to hidden label
		hidden_label.config(text=f'Hello {my_entry.get()}')
		# Delete The Entry Box
		my_entry.delete(0, END)

	else:
		# Error message
		hidden_label.config(text="Hey! You Forgot To Enter Your Name!")

# Create a Label
my_label = Label(root, text="Enter Your Name", font=("Helvetica", 24))
my_label.pack(pady=20)

# Create an Entry Box
my_entry = Entry(root, width=20, font=("Helvetica", 24))
my_entry.pack(pady=20)

# Create a Button
my_button = Button(root, text="Answer", command=answer)
my_button.pack(pady=5)

insert_button = Button(root, text="Insert John", command=insert)
insert_button.pack(pady=5)

# Create a hidden label
hidden_label = Label(root, text="", font=("Helvetica", 18))
hidden_label.pack(pady=20)



root.mainloop()



John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of the first dot com boom. After that he developed the award-winning Submission-Spider search engine submission software that's been used by over 3 million individuals, businesses, and governments in over 42 countries. He's written several Amazon #1 best selling books on coding, and runs a popular Youtube coding channel.

View all posts

Add comment

Your email address will not be published. Required fields are marked *

John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of...