How to get the desktop resolution in Mac via Python?

前端 未结 4 1441
渐次进展
渐次进展 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条回答
  •  旧时难觅i
    2021-02-15 14:43

    I was having a hard time getting any of this to work so I looked around and put something together that seems to work. I am kinda new at coding so please excuse any errors. If you have any thoughts please comment.

    results = str(subprocess.Popen(['system_profiler SPDisplaysDataType'],stdout=subprocess.PIPE, shell=True).communicate()[0])
    res = re.search('Resolution: \d* x \d*', results).group(0).split(' ')
    width, height = res[1], res[3]
    return width, height
    

提交回复
热议问题