如何通过Python在Mac中获得桌面分辨率? [英] How to get the desktop resolution in Mac via Python?

查看:344
本文介绍了如何通过Python在Mac中获得桌面分辨率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试编写一个Python应用程序,该应用程序从RSS提要中下载图像,并制作合成背景.如何在Mac OS X(豹)上获得当前的桌面分辨率?

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?)

推荐答案

对于Pyobjc,类似的东西应该可以工作. Pyobjc带有豹子.

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

例如:

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

这篇关于如何通过Python在Mac中获得桌面分辨率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆