在Ubuntu上用Python获取Monitor分辨率

rec*_*gle 4 python ubuntu resolution monitor

对于Ubuntu,win32api中的GetSystemMetrics是否有相同的代码?我需要以像素为单位获取显示器的宽度和高度.

pyf*_*unc 5

我可以建议一些可以使用的方法.我没有使用xlib版本.

1)xlib(Python程序的X客户端库),如果在您的系统上可用.您可以查看"显示"方法和属性:python-xlib.sourceforge

2)在Ubuntu上,您可以执行以下操作来获取屏幕分辨率:

   xrandr  | grep \* | cut -d' ' -f4
Run Code Online (Sandbox Code Playgroud)

3)您可以使用子进程python模块,运行上面的命令并提取信息

import subprocess
output = subprocess.Popen('xrandr | grep "\*" | cut -d" " -f4',shell=True, stdout=subprocess.PIPE).communicate()[0]
print output
Run Code Online (Sandbox Code Playgroud)

如果这对您有帮助,请告诉我.


loe*_*org 5

我假设你是一个GUI工具包.为什么你会对屏幕尺寸感兴趣?

退房gtk.gdk.screen_width()gtk.gdk.screen_height()从PyGTK.类似的东西应该可用于QT.