To change the default Tkinter window size in python, we can use either the funtion “root.geometry()” or a combination of “tk.canvas()” and “canvas.grid()“.
Tkinter’s geometry function is by far one of the most common ways to set the window size of your program. The function works by setting the dimensions through its widthxheight attribute.
widthxheight: input the width and height ratio through a string format
As shown in the output below we can see tinker’s size has increased larger than its original size.
tk.canvas() and canvas.grid()
Another less conventional way to resize the window size is by using a combination of “tk.canvas()” and “canvas.grid()”.
Tkinter’s canvas function is actually prebuilt to draw geometry shapes, however, it can be suitable for many use cases, one of which is the ability to resize the shape of your window.
However, this will only work once we specify and declare our canvas.grid() function, which is essentially an array for us to align our items within our window.
Syntax: tk.canvas(root, bg, height, width)
Parameters (most commonly used ones):
root: the function in which your root is stored in
bg: color of the shape
height: the height of your window
width: the width of your window
syntax: canvas.grid(columnspan, rowspan)
columnspan: the number of columns within the window
rowspan: the number of rows within the window