Tkinter

How to Set The Width and Height of a Tkinter Entry

In this tutorial, we are going to see how to set the width and height of a Tkinter Entry. The Entry widget is used to enter text. This widget allows the user to enter one line of text. To enter multiple lines of text, use the Text widget.

Normally we don’t need to set the height of the Entry widget. But there are some methods to set the height and width of the Entry widget.
 

 

Example 1: How to Set The Width of a Tkinter Entry

If we want to set only the width of the Entry widget, we use the ‘width’ option of the Entry widget.

import tkinter as tk

gui = tk.Tk()
gui.geometry("300x100")

myEntry = tk.Entry(gui, width=40)
myEntry.pack(pady=20)

gui.mainloop()

Output:


 
 

Example 2: How to Set The Width and Height of a Tkinter Entry

The geometry method place() sets the width and height of the Entry widget in pixels.

import tkinter as tk

gui = tk.Tk()
gui.geometry("300x150")

myEntry = tk.Entry(gui)
myEntry.place(x=10, y=10, width=280, height=100)

gui.mainloop()

Output:


 
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *