How to set the width of a Tkinter Entry widget in pixels?

Tkinter has an Entry widget to accept single-line user input. It has many properties and attributes that can be used to configure the Entry widget. To change the size (width or height of the Entry widget), we can use Internal Padding Properties – ipadx and ipady. By defining the value of internal padding, we can actually change the width and height of the Entry widget.


#Import the required Libraries
from tkinter import *
from tkinter import ttk
#Create an instance of tkinter frame
win = Tk()
#Set the geometry of tkinter frame

#Define a function to submit the validate the value of Entry widget
def submit_name():
   Label(frame, text="Hello "+ entry.get(), font=('Helvetica',12, 'bold')).pack(pady=20)
   submit.configure(state= "disabled")

#Creates a Frame
frame = LabelFrame(win, width= 400, height= 180, bd=3)
#Create an Entry widget in the Frame for Accepting the Username
entry = ttk.Entry(frame, width= 40)
entry.insert(INSERT, "Enter Your Name")
entry.pack(ipadx= 30, ipady=30)

#Set the focus on Entry1

#Create a submit button
submit= ttk.Button(win, text= "submit",command=submit_name)


Run the above code to display the Entry widget which has some internal padding in it.

In the given output, we will click the "submit" button and it will display the greeting message as the output on the screen.

Updated on 03-May-2021 09:15:13