在Ubuntu的win32api中,有没有等同于GetSystemMetrics的代码?我需要以像素为单位获取显示器的宽度和高度。
发布于 2010-08-30 07:33:44
我假设您是一个GUI工具包。你为什么会对屏幕尺寸感兴趣呢?
查看来自PyGTK的gtk.gdk.screen_width()
和gtk.gdk.screen_height()
。类似的东西应该可以在QT上使用。
发布于 2010-08-30 06:25:24
我可以建议一些可以使用的方法。不过,我还没有使用xlib版本。
1) xlib ( Python程序的X客户端库),如果在您的系统上可用。您可以查看“显示”方法和属性:python-xlib.sourceforge
2)在Ubuntu上,可以通过以下方式获取屏幕分辨率:
xrandr | grep \* | cut -d' ' -f4
3)可以使用子进程python module,运行上述命令并提取信息
import subprocess
output = subprocess.Popen('xrandr | grep "\*" | cut -d" " -f4',shell=True, stdout=subprocess.PIPE).communicate()[0]
print output
如果这对你有帮助,请告诉我。
发布于 2015-11-14 20:59:24
import subprocess
def get_screen_resolution():
output = subprocess.Popen('xrandr | grep "\*" | cut -d" " -f4',shell=True, stdout=subprocess.PIPE).communicate()[0]
resolution = output.split()[0].split(b'x')
return {'width': resolution[0], 'height': resolution[1]}
print(get_screen_resolution())
resolution[0]
将是类似于b'1020‘的字节格式。要将其转换为整数格式,请尝试int(resolution[0].decode('UTF-8'))
。
https://stackoverflow.com/questions/3597965
复制相似问题