Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Monitor resolution in Python on Ubuntu

Is there a equatable bit of code to GetSystemMetrics in win32api, for Ubuntu? I need to get the monitors width and height in pixels.

like image 585
rectangletangle Avatar asked Dec 08 '22 01:12

rectangletangle


1 Answers

I can suggest a few approaches that can be used. I have not used the xlib version though.

1) xlib ( X client library for Python programs), if available on your system. You can look at "Display" methods and properties : python-xlib.sourceforge

2) On Ubuntu, you could do the following to get the screen resolution:

   xrandr  | grep \* | cut -d' ' -f4

3) You can use subprocess python module, to run the above command and extract the information

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

Let me know, if this was helpful to you.

like image 126
pyfunc Avatar answered Dec 09 '22 14:12

pyfunc