Open In App

How to resize an Entry Box by height in Tkinter?

Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we shall look at how can one resize the height of an Entry Box in Python Tkinter

An Entry Widget is a widget using which a user can enter text, it is similar to HTML forms. In Tkinter, the Entry widget is a commonly used Text widget, using which we can perform set() and get() methods. But the developer might always find it annoying with the default size of the Entry Box. There are two different ways using which you can resize the Entry Box by its height. 

Method 1: By Increasing Font Size

A font is a graphical representation of text that may include different types, sizes, weights, or colors. font can be passed as an argument in many Tkinter widgets. Changing the font is optional in creating Tkinter but many developers do not prefer the default font.  Here is the syntax of assigning font to Tkinter widgets. 

Syntax:

tkinter.widget(font=("font name",font size,"font weight"))
# must follow the order: name,size,weight (inside a tuple)
# additional arguments fg: foreground color; bg: background
# color

By increasing the size of the height you can eventually increase the size of the height. By decreasing the font size you will end up decreasing the height of the font box. 

Python3




import tkinter as tk
  
root = tk.Tk()
  
# dimension of the GUI application
root.geometry("300x300")
  
# to make the GUI dimensions fixed
root.resizable(False, False)
  
# increase font size to increase height of entry box
using_font_resize = tk.Entry(font=("arial", 24), fg="white", bg="black")
using_font_resize.pack()
  
root.mainloop()


Output:

Method 2: By Using the place() layout manager

The place() is a layout manager in Tkinter just like pack() and grid(). The best thing about place manager is you can place the widget anywhere within the widget. place() method usually takes 4 arguments: x, y, width, and height. x and y are used to specify the position to place the widget whereas width and height are used to alter the dimension of the widget. All these arguments take integer values. 

Since the default size of the Entry Box is small we can increase its width and height value.

Syntax:

widget.place(x=int,y=int,width=int,height=int)

Python3




import tkinter as tk
  
root = tk.Tk()
  
# dimension of the GUI application
root.geometry("300x300")
  
# to make the GUI dimensions fixed
root.resizable(False, False)
  
# this is default entry box size
default_entry_box = tk.Entry(bg="blue", fg="white")
default_entry_box.pack()
  
# this is resized entry box with height 60
resizedHeight = tk.Entry(bg="green", fg="white")
resizedHeight.place(x=40, y=100, width=180, height=60)
  
root.mainloop()


Output:



Last Updated : 18 Mar, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads