How do I get monitor resolution in Python?

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

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

30条回答
  •  醉酒成梦
    2020-11-22 14:29

    In Windows, you can also use ctypes with GetSystemMetrics():

    import ctypes
    user32 = ctypes.windll.user32
    screensize = user32.GetSystemMetrics(0), user32.GetSystemMetrics(1)
    

    so that you don't need to install the pywin32 package; it doesn't need anything that doesn't come with Python itself.

    For multi-monitor setups, you can retrieve the combined width and height of the virtual monitor:

    import ctypes
    user32 = ctypes.windll.user32
    screensize = user32.GetSystemMetrics(78), user32.GetSystemMetrics(79)
    

提交回复
热议问题