Tkinter

How to Set Tkinter Window Size – Python

In this tutorial, we are going to see how to set Tkinter window size in Python. In general, when you create a GUI using Tkinter, the size of the window relies on the size and position of the elements in the window. However, you can also manage the size of the window by setting a specific width and height for the window.

You can set the size of the Tkinter window by calling the geometry() function on the window with a “width x height” string passed as an argument.

In this tutorial, we are going to see how to set a custom window size to our Tkinter GUI application in Python, using the following examples.
 

 

Syntax:

You can apply geometry() function on Tk() class variable to set a custom window size when using Python tkinter. See the following syntax.

from tkinter import *
#create a class variable Tk()
gui = Tk()
#set the size of the window
gui.geometry("width x height")

Where width and height should be integers that show the width and height of the window respectively. Note that there is an ‘x’ character between width and height in the parameter to geometry().
 

 

Example :

In the following example, we are going to use geometry() method to set a fixed window size of 400 x 300 to the Tk() window.

from tkinter import *

gui = Tk()

#set the size of the window
gui.geometry("400x300")

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 *