Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to resize an Entry Box by height in Tkinter?
An Entry widget in a Tkinter application supports single-line user inputs. You can configure the size of an Entry widget such as its width using the width property. However, Tkinter has no height property to set the height of an Entry widget. To set the height, you can use the font('font_name', font-size) property. The font size of the text in an Entry widget always works as a height of the Entry widget.
Example
Let us take an example to understand this more clearly. Follow the steps given below ?
Import the required libraries
Create an Entry widget, set its width and height by specifying the font('font-name', font-size) property.
Create a Button to print the name of the user with the help of a Label widget.
Define a function to create a Label to display the name of the users.
Use the
get()function to return the string input from the Entry widget.
# Import the required libraries
from tkinter import *
# Create an instance of tkinter frame
win = Tk()
# Set the size of the tkinter window
win.geometry("700x350")
# Define a function
def myClick():
greet = "Hello " + name.get()
label = Label(win, text=greet, font=('Arial', 12))
label.pack(pady=10)
# Create an entry widget with increased height using font size
name = Entry(win, width=50, font=('Arial', 24))
name.pack(padx=10, pady=10)
# Create a button
button = Button(win, text="Submit", command=myClick)
button.pack(pady=10)
win.mainloop()
Output
Running the above program will display a window with an Entry widget asking users to enter their name and a Button to submit the name. When you hit "Submit", it will display a Label widget on the screen ?
Alternative Methods
Using Different Font Sizes
You can create Entry widgets with different heights by varying the font size ?
from tkinter import *
root = Tk()
root.geometry("400x300")
# Small Entry (default height)
small_entry = Entry(root, width=30, font=('Arial', 10))
small_entry.pack(pady=10)
# Medium Entry
medium_entry = Entry(root, width=30, font=('Arial', 16))
medium_entry.pack(pady=10)
# Large Entry
large_entry = Entry(root, width=30, font=('Arial', 24))
large_entry.pack(pady=10)
root.mainloop()
Using ipady Parameter
Another approach is to use the ipady parameter in the pack() method to add internal padding ?
from tkinter import *
root = Tk()
root.geometry("400x200")
# Entry with internal padding for extra height
entry_with_padding = Entry(root, width=30, font=('Arial', 12))
entry_with_padding.pack(pady=10, ipady=10)
root.mainloop()
Comparison
| Method | Pros | Cons |
|---|---|---|
| Font Size | Text scales proportionally | Changes text appearance |
| ipady Parameter | Maintains text size | Limited height control |
Conclusion
To resize an Entry widget's height in Tkinter, use the font parameter with larger font sizes. Alternatively, use ipady for internal padding while maintaining text size.
