How to get the desktop resolution in Mac via Python?

前端 未结 4 1501
渐次进展
渐次进展 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:45

    With Pyobjc something like this should work. Pyobjc comes with Leopard.

    from AppKit import NSScreen
    print(NSScreen.mainScreen().frame())
    

    With that, you can also grab the width and height.

    NSScreen.mainScreen().frame().size.width
    NSScreen.mainScreen().frame().size.height
    

    For example:

    print("Current screen resolution: %dx%d" % (NSScreen.mainScreen().frame().size.width, NSScreen.mainScreen().frame().size.height))
    

提交回复
热议问题