Tkinter Entry - Set Width


Tkinter Entry - Set Width

In Tkinter, you can set the width of an Entry widget to specific number of characters.

Tkinter Entry - Set Width
Tkinter Entry with width=30

To set the width of an Entry widget to specific number of characters, set the width parameter to required value when creating Entry using tk.Entry().

For example, the following code creates an Entry widget of 30 characters wide.

tk.Entry(window, width=30)

In this tutorial, you will learn how to set the width of an Entry widget, with examples.

Examples

1. Set Entry widget's width to 30

In this example, we create a basic Tk window with an Entry widget and set its width to 30.

Python Program

import tkinter as tk

# Create the main window
window = tk.Tk()
window.title("PythonExamples.org")
window.geometry("350x250")

label = tk.Label(window, text="Enter your input")
label.pack()

# Create an Entry widget with specific width
entry = tk.Entry(window, width=30)
entry.pack()

# Run the application
window.mainloop()

Output

In Windows

In MacOS

Tkinter Entry with width=30
Tkinter Entry with width=30

Summary

In this Python Tkinter tutorial, we have seen how to set the font size of an Entry widget in Tkinter, with examples.