Home > python > get screen resolution

get screen resolution

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.

About these ads
  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.
Follow

Get every new post delivered to your Inbox.

Join 61 other followers

%d bloggers like this: