How do I get monitor resolution in Python?

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

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

30条回答
  •  春和景丽
    2020-11-22 14:39

    Another version using xrandr:

    import re
    from subprocess import run, PIPE
    
    output = run(['xrandr'], stdout=PIPE).stdout.decode()
    result = re.search(r'current (\d+) x (\d+)', output)
    width, height = map(int, result.groups()) if result else (800, 600)
    

提交回复
热议问题