问题
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