How do I get monitor resolution in Python?

rectangletangle picture rectangletangle · Jun 28, 2010 · Viewed 179.1k times · Source

What is the simplest way to get monitor resolution (preferably in a tuple)?

Answer

jcao219 picture jcao219 · Jun 28, 2010

In Windows, you can also use ctypes with GetSystemMetrics():

import ctypes
user32 = ctypes.windll.user32
screensize = user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)

so that you don't need to install the pywin32 package; it doesn't need anything that doesn't come with Python itself.

For multi-monitor setups, you can retrieve the combined width and height of the virtual monitor:

import ctypes
user32 = ctypes.windll.user32
screensize = user32.GetSystemMetrics(78), user32.GetSystemMetrics(79)