How do I get monitor resolution in Python?

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

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

30条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-22 14:39

    I created a PyPI module for this reason:

    pip install screeninfo
    

    The code:

    from screeninfo import get_monitors
    for m in get_monitors():
        print(str(m))
    

    Result:

    monitor(1920x1080+1920+0)
    monitor(1920x1080+0+0)
    

    It supports multi monitor environments. Its goal is to be cross platform; for now it supports Cygwin and X11 but pull requests are totally welcome.

提交回复
热议问题