How to get the desktop resolution in Mac via Python?

前端 未结 4 1430
渐次进展
渐次进展 2021-02-15 13:52

Trying to write a python application that downloads images from an RSS feed, and makes a composite background. How do I get the current desktop resolution on Mac OS X (leopard?)

4条回答
  •  时光说笑
    2021-02-15 14:38

    As usual, using features that are binded to an OS is a very bad idea. There are hundred of portable libs in Python that give you access to that information. The first that comes to my mind is of course pygame :

    import pygame
    from pygame.locals import *
    
    pygame.init()
    screen = pygame.display.set_mode((640,480), FULLSCREEN)
    x, y = screen.get_size()
    

    But I guess cocoa do just as good, and therefor wxpython or qt is your friend. I suppose on Windows you did something like this :

    from win32api import GetSystemMetrics
    width = GetSystemMetrics [0]
    height = GetSystemMetrics [1]
    

    Sure it's easier, but won't work on Mac, Linux, BSD, Solaris, and probably nor very later windows version.

提交回复
热议问题