How do I get monitor resolution in Python?

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

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

30条回答
  •  爱一瞬间的悲伤
    2020-11-22 14:28

    Old question but this is missing. I'm new to python so please tell me if this is a "bad" solution. This solution is supported for Windows and MacOS only and it works just for the main screen - but the os is not mentioned in the question.

    Measure the size by taking a screenshot. As the screensize should not change this has to be done only once. There are more elegant solutions if you have a gui toolkit like GTK, wx, ... installed.

    see Pillow

    pip install Pillow
    

    from PIL import ImageGrab
    
    img = ImageGrab.grab()
    print (img.size)
    

提交回复
热议问题