Archive
Posts Tagged ‘screen resolution’
get screen resolution
March 27, 2012
Leave a comment
Problem
You need the current screen resolution.
Solution #1 (command-line)
xrandr | grep '*'
Sample output:
1920x1080 50.0* 51.0 52.0
This tip is from here.
Solution #2 (Python)
Let’s see the previous solution in Python:
from jabbapylib.process import process
def get_screen_resolution():
"""
Screen resolution (as a tuple).
"""
result = [x for x in process.get_simple_cmd_output('xrandr').split('\n') if '*' in x][0]
result = tuple([int(x) for x in result.split()[0].split('x')])
return result
Sample output:
(1920, 1080)
process.get_simple_cmd_output is part of my jabbapylib library. get_simple_cmd_output() simply executes an external command and returns its output as a string.
Categories: python
command-line, screen resolution, xrandr
