Resolution of a maximized window in Python Resolution of a maximized window in Python tkinter tkinter

Resolution of a maximized window in Python


According to [MS.Docs]: GetSystemMetrics function (emphasis is mine):

SM_CXFULLSCREEN

16

The width of the client area for a full-screen window on the primary display monitor, in pixels. To get the coordinates of the portion of the screen that is not obscured by the system taskbar or by application desktop toolbars, call the SystemParametersInfo function with the SPI_GETWORKAREA value.

Same thing for SM_CYFULLSCREEN.

Example:

>>> import ctypes as ct>>>>>>>>> SM_CXSCREEN = 0>>> SM_CYSCREEN = 1>>> SM_CXFULLSCREEN = 16>>> SM_CYFULLSCREEN = 17>>>>>> user32 = ct.windll.user32>>> GetSystemMetrics = user32.GetSystemMetrics>>>>>> # @TODO: Never forget about the 2 lines below !!!>>> GetSystemMetrics.argtypes = [ct.c_int]>>> GetSystemMetrics.restype = ct.c_int>>>>>> GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)  # Entire (primary) screen(1920, 1080)>>> GetSystemMetrics(SM_CXFULLSCREEN), GetSystemMetrics(SM_CYFULLSCREEN)  # Full screen window(1920, 1017)

Regarding the @TODO in the code: check [SO]: C function called from Python via ctypes returns incorrect value (@CristiFati's answer).


If you don't want the window to persist simply remove the mainloop method from the tkinter code.

import tkinter as tkroot = tk.Tk()  # Create an instance of the class.root.state('zoomed')  # Maximized the window.root.update_idletasks()  # Update the display.screensize = [root.winfo_width(), root.winfo_height()]

I also found this that might be helpful and more what you are looking for; I am using Linux, so I am unable to test it.

from win32api import GetSystemMetricsprint("Width =", GetSystemMetrics(0))print("Height =", GetSystemMetrics(1))

How do I get monitor resolution in Python?