问题描述
我想要整个桌面的 X/Y 像素尺寸(可能跨越多个显示器),例如确定背景图像的最佳分辨率。
此 Python 代码仍然有效:
from gi import require_version
require_version("Gdk","3.0")
from gi.repository import Gdk
screen = Gdk.Screen.get_default()
print(screen.get_width()," ",screen.get_height())
但会打印弃用警告:
<string>:7: DeprecationWarning: Gdk.Screen.get_width is deprecated
<string>:7: DeprecationWarning: Gdk.Screen.get_height is deprecated
Gdk.Screen API docs 只是注意:
自 3.22 版起已弃用:改为使用每个显示器的信息
其他答案(如 How do I get monitor resolution in Python 或 How to detect a computer's physical screen size in GTK)提到了许多其他 API 和工具包,或者只是提供每个显示器的信息(如 this for PyGtk),但我认为它仍然应该是可能(将来也会)通过 PyGtk 获取整个桌面的尺寸。 (毕竟,弃用的功能也仍然提供这个。)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)