Python Tkinter – Set Entry width 100%

Tkinter Entry widgets accept single-line user input in a text field. We can change the properties of the Entry widget by providing the default attributes and values in its constructor.

When creating GUI applications, you often need Entry widgets that span the full width of the container. The Pack geometry manager provides several ways to achieve this using the fill parameter.

Using fill='x' Parameter

The simplest way to create a full-width Entry widget is using the fill='x' parameter with the pack method ?

# Import the required library
from tkinter import *
from tkinter import ttk

# Create an instance of tkinter frame or window
win = Tk()

# Set the size of the window
win.geometry("700x350")

# Add label widget in the application
label = Label(win, text="Enter Your Name")
label.pack()

# Add an entry widget with full width
entry = Entry(win)
entry.pack(fill='x')

win.mainloop()

Adding Padding with Full Width

You can combine full width with padding to create better visual spacing ?

from tkinter import *

# Create main window
win = Tk()
win.geometry("600x300")
win.title("Full Width Entry with Padding")

# Add label
label = Label(win, text="Enter Your Email", font=("Arial", 12))
label.pack(pady=(20, 5))

# Add full-width entry with padding
entry = Entry(win, font=("Arial", 11))
entry.pack(fill='x', padx=20, pady=5)

# Add another entry
label2 = Label(win, text="Enter Your Address", font=("Arial", 12))
label2.pack(pady=(10, 5))

entry2 = Entry(win)
entry2.pack(fill='x', padx=20, pady=5)

win.mainloop()

Using expand Parameter

For more flexible resizing behavior, combine fill='x' with expand=True ?

from tkinter import *

win = Tk()
win.geometry("500x200")
win.title("Expandable Entry Widget")

# Frame to contain the entry
frame = Frame(win)
frame.pack(fill='x', padx=10, pady=10)

label = Label(frame, text="Resizable Entry:")
label.pack()

# Entry that expands with window resizing
entry = Entry(frame, bg="lightyellow")
entry.pack(fill='x', expand=True, pady=5)

win.mainloop()

Comparison of Width Options

Method Behavior Best For
fill='x' Fills available horizontal space Fixed layouts
fill='x', expand=True Expands when window resizes Resizable interfaces
width=N Fixed character width Specific size requirements

Conclusion

Use pack(fill='x') to create full-width Entry widgets that span the container horizontally. Combine with padx and pady for better spacing, and add expand=True for resizable layouts.

Updated on: 2026-03-25T22:16:18+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements