How do I get monitor resolution in Python?

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

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

30条回答
  •  庸人自扰
    2020-11-22 14:26

    To get bits per pixel:

    import ctypes
    user32 = ctypes.windll.user32
    gdi32 = ctypes.windll.gdi32
    
    screensize = (user32.GetSystemMetrics(0), user32.GetSystemMetrics(1))
    print "screensize =%s"%(str(screensize))
    dc = user32.GetDC(None);
    
    screensize = (gdi32.GetDeviceCaps(dc,8), gdi32.GetDeviceCaps(dc,10), gdi32.GetDeviceCaps(dc,12))
    print "screensize =%s"%(str(screensize))
    screensize = (gdi32.GetDeviceCaps(dc,118), gdi32.GetDeviceCaps(dc,117), gdi32.GetDeviceCaps(dc,12))
    print "screensize =%s"%(str(screensize))
    

    parameters in gdi32:

    #/// Vertical height of entire desktop in pixels
    #DESKTOPVERTRES = 117,
    #/// Horizontal width of entire desktop in pixels
    #DESKTOPHORZRES = 118,
    #/// Horizontal width in pixels
    #HORZRES = 8,
    #/// Vertical height in pixels
    #VERTRES = 10,
    #/// Number of bits per pixel
    #BITSPIXEL = 12,
    

提交回复
热议问题