如何使用python计算屏幕(宽度,高度)中的像素数?
我希望它适用于任何屏幕,这可能吗?
答案 0 :(得分:1)
借用这个问题:How do I get monitor resolution in Python?,有几种选择。这是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
other post有很多不同的方法,包括获取有关多显示器设置,Windows操作系统实现,DPI等的信息。
答案 1 :(得分:1)
这里是只有两行代码的解决方案:
import pyautogui
print(pyautogui.size())
PyAutoGUI是一个非常有用的模块,用于以编程方式控制鼠标和键盘。
访问网站here