How do I get monitor resolution in Python?

后端 未结 30 1547
深忆病人
深忆病人 2020-11-22 13:49

What is the simplest way to get monitor resolution (preferably in a tuple)?

30条回答
  •  礼貌的吻别
    2020-11-22 14:37

    Using Linux Instead of regexp take the first line and take out the current resolution values.

    Current resolution of display :0

    >>> screen = os.popen("xrandr -q -d :0").readlines()[0]
    >>> print screen
    Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 1920 x 1920
    >>> width = screen.split()[7]
    >>> print width
    1920
    >>> height = screen.split()[9][:-1]
    >>> print height
    1080
    >>> print "Current resolution is %s x %s" % (width,height)
    Current resolution is 1920 x 1080
    

    This was done on xrandr 1.3.5, I don't know if the output is different on other versions, but this should make it easy to figure out.

提交回复
热议问题