How do I set the window size in tkinter?
One call, before mainloop(). The string is width by height in pixels, with a lowercase x between them — not a multiplication sign, and not a tuple.
import tkinter as tk
root = tk.Tk()
root.title("My Application")
root.geometry("520x380")
root.mainloop() Position it as well as size it
The same string takes an optional position: "520x380+300+120" opens the window 300 pixels from the left of the screen and 120 down from the top. Leave the position off and the window manager decides, which is normal behaviour and usually the right choice.
root.geometry("520x380+300+120")Centre it on the screen
There is no centre option, so you work it out from the screen size. Ask the window how big the screen is, subtract your own size, and halve it.
w, h = 520, 380
x = (root.winfo_screenwidth() - w) // 2
y = (root.winfo_screenheight() - h) // 2
root.geometry(f"{w}x{h}+{x}+{y}")Stop it being resized
resizable takes two booleans, one per axis, so you can lock the height and still allow width. minsize and maxsize set bounds instead of freezing it outright.
root.resizable(False, False) # neither direction
root.minsize(400, 300) # or just set limitsWhen the window ignores the size you asked for
A window sized with geometry() still grows if a widget inside it will not fit — tkinter treats your number as a starting point, not a hard limit. If the window opens bigger than you asked, something inside is demanding the space. Use pack_propagate(False) or grid_propagate(False) on the container to stop it, or give the offending widget a smaller size.
The other common surprise: calling geometry() after mainloop() has started does nothing visible, because mainloop() blocks. Set it before.
Doing it without the lookup
Width and height are two boxes in the inspector, and the canvas is that size as you draw on it, so you are never guessing. "Opens at" covers the position — leave it to the OS, centre it, or pin it to fixed coordinates — and the export contains the matching geometry() call.
Lay the window out visually and read the generated Python as you go.
Open the tkinter designer →