Home > python > get screen resolution

get screen resolution

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.

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: