Number of pixels of screen python

那年仲夏 提交于 2019-12-12 01:23:16

问题


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?


回答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.




回答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



来源:https://stackoverflow.com/questions/41834451/number-of-pixels-of-screen-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!