in ,

Python GUI - How to Create Fields Using Tkinter?

Fields are created with Entry() method in the Python using Tkinter library. The below is an example of a Python program for creating fields using Tkinter.

Create Fields in Python Using Tkinter Example

In the following example, it will create four fields to ask first name, last name, e-mail, and phone number. Python program version used is 3.7.

from tkinter import *

window = Tk()

window.title("Main Window")
window.configure(width=500, height=300, bg="gray")
window.geometry("500x300")

a = ""
label0 = Label(window, text=a, bg="gray")
label0.grid()

label1 = Label(window, text="First Name:", bg="gray", fg="white")
label1.grid(row=1, column=0)
entry1 = Entry(window)
entry1.grid(row=1, column=1)
label2 = Label(window, text="Last Name:", bg="gray", fg="white")
label2.grid(row=1, column=2)
entry2 = Entry(window)
entry2.grid(row=1, column=3)
label3 = Label(window, text="Email: ", bg="gray", fg="white")
label3.grid(row=3, column=0)
entry3 = Entry(window)
entry3.grid(row=3, column=1)
label4 = Label(window, text="Phone:", bg="gray", fg="white")
label4.grid(row=3, column=2)
entry4 = Entry(window)
entry4.grid(row=3, column=3)

# set the focus to the first entry
entry1.focus_set()

window.mainloop()

Output

Tkinter create fields example

See also:

What do you think?

289 Points
Upvote Downvote

How to Add Comments to a Table in Oracle SQL Developer?

Python DictReader Examples