Alex Rivera | Logout

How do I get monitor resolution in Python?

Asked 2010-06-27T23:39:21.630
209

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

Edit
Report

3 Answers

159

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)
answered 2010-06-28T00:54:26.030
69

Taken directly from an answer to the post How can I get the screen size in Tkinter?,

import tkinter as tk

root = tk.Tk()

screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
answered 2013-05-13T19:29:23.663
17

If you are using the Qt toolkit, specifically PySide, you can do the following:

from PySide import QtGui
import sys

app = QtGui.QApplication(sys.argv)
screen_rect = app.desktop().screenGeometry()
width, height = screen_rect.width(), screen_rect.height()
answered 2013-07-04T16:42:51.857

Your Answer