How do I get monitor resolution in Python?

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

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

30条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 14:32

    If you are working on Windows OS, you can use OS module to get it:

    import os
    cmd = 'wmic desktopmonitor get screenheight, screenwidth'
    size_tuple = tuple(map(int,os.popen(cmd).read().split()[-2::]))
    

    It will return a tuple (Y,X) where Y is the vertical size and X is the horizontal size. This code works on Python 2 and Python 3

提交回复
热议问题