Skip to content Skip to sidebar Skip to footer

Number Of Pixels Of Screen Python

How can I calculate the number of pixels in screen (width, height) with python? I want it to be adaptable to any screen, is this possible?

Solution 1:

Borrowing from this question: How do I get monitor resolution in Python?, there are several options. Here's one with Tkinter:

import Tkinter as tk

root = tk.Tk()

screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()

print screen_width * screen_height # (e.g.) 3686400 = 2560*1440

That other post has a lot of different ways to do it, including getting information about multi-monitor setup, Windows OS implementations, DPI, etc.

Solution 2:

Here is a solution with only two lines of code:

import pyautogui
print(pyautogui.size())

PyAutoGUI is a pretty useful module for programmatically controlling the mouse and keyboard.

Check out the website for it here

Post a Comment for "Number Of Pixels Of Screen Python"