How to Set Height and Width of Tkinter Entry Widget

Jinku Hu Feb 02, 2024
  1. width Option in Entry Widget to Set the Width
  2. width and height Option in place Geometry Method to Set width and height of Tkinter Entry Widget
  3. ipadx and ipady Options in pack and grid Method to Set the Width and Height of Tkinter Entry Widget
How to Set Height and Width of Tkinter Entry Widget

Tkinter Entry widget is the widget to let the user enter or display a single line of text. Therefore it normally doesn’t need to set the height of the Entry widget. But it has some methods to set the height and also the width of Tkinter Entry widget.

  1. width option in Entry widget to set the width
  2. width and height options in place method to set the width and height of Tkinter Entry widget
  3. ipadx and ipady options in pack and grid method to set the width and height of Tkinter Entry widget

width Option in Entry Widget to Set the Width

If only the width of Entry widget needs to be specified, width option in Entry widget could be the simplest method.

import tkinter as tk

app = tk.Tk()
app.geometry("400x200")

entryExample = tk.Entry(app, width=10)

entryExample.pack(side=tk.LEFT, padx=10)

app.mainloop()

Tkinter Entry width option

The unit of width option in Tkinter Entry widget is text units but not pixels. One text unit in the width is equal to the width of 0 in the system font. That’s why it could display 10 zero’s in the above image when the width is set to be 10.

width and height Option in place Geometry Method to Set width and height of Tkinter Entry Widget

width and height in place geometry method sets the width and height of the widget, in the unit of pixels.

import tkinter as tk

app = tk.Tk()
app.geometry("400x200")

entryExample = tk.Entry(app)
entryExample.place(x=10, y=10, width=200, height=100)

app.mainloop()

Tkinter Entry_width and height option in place method

ipadx and ipady Options in pack and grid Method to Set the Width and Height of Tkinter Entry Widget

ipadx and ipady sets the internal padding in the horizontal and vertical direction. It could set the width and height of Tkinter Entry widget indirectly.

The geometry of Tkinter Entry widget with grid method is as below,

Tkinter Entry_width and height in grid method

The actual width of the Tkinter Entry is 2*ipadx + Default Entry width, similarly the actual width of Entry is 2*ipady + Default Entry height.

import tkinter as tk

app = tk.Tk()

entryExample1 = tk.Entry(app)
entryExample2 = tk.Entry(app)

entryExample1.grid(row=0, column=0, padx=10, pady=10, ipady=30)

entryExample2.grid(row=1, column=0, padx=10, pady=10, ipadx=20, ipady=30)

app.geometry("200x200")

app.mainloop()

Tkinter Entry_ipadx in grid method

As you could see, because entryExample2 has ipadx as 20 meanwhile ipadx of entryExample1 is by default 0, therefore, the width of entryExample2 is 40 pixels wider than entryExample1.

We could similarly set the ipady to change the width of Tkinter Entry widget.

import tkinter as tk

app = tk.Tk()

entryExample1 = tk.Entry(app)
entryExample2 = tk.Entry(app)

entryExample1.grid(row=0, column=0, padx=10, pady=10, ipady=50)

entryExample2.grid(row=0, column=1, padx=10, pady=10, ipady=60)

app.geometry("300x200")

app.mainloop()

Tkinter Entry_ipady in grid method

Author: Jinku Hu
Jinku Hu avatar Jinku Hu avatar

Founder of DelftStack.com. Jinku has worked in the robotics and automotive industries for over 8 years. He sharpened his coding skills when he needed to do the automatic testing, data collection from remote servers and report creation from the endurance test. He is from an electrical/electronics engineering background but has expanded his interest to embedded electronics, embedded programming and front-/back-end programming.

LinkedIn Facebook

Related Article - Tkinter Entry