7中win32gui的替代方法

7中win32gui的替代方法

本文介绍了什么是Mac上python 2.7中win32gui的替代方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用win32gui来确定某个特定的窗口是否已在Windows中打开.我也想在Mac OS中具有相同的功能.在Windows中 导入win32gui win32gui.FindWindow(类名,窗口名)

I am using win32gui for figuring out that a specific window has been opened or not in Windows. I want to have same functionality in mac os also.In Windows import win32gui win32gui.FindWindow(class_name, window_name)

对于Mac OS,python 2.7中的等效lib是什么?

what is equivalent lib in python 2.7 for mac os?

推荐答案

我找到了上述问题的解决方案

I found solution for above problem

from Quartz import CGWindowListCopyWindowInfo, kCGNullWindowID, kCGWindowListOptionAll
import datetime, time
print datetime.datetime.now()
found = False
count = 0
windowName = "Hello World"
while 1:
    list = CGWindowListCopyWindowInfo(kCGWindowListOptionAll, kCGNullWindowID)
time.sleep(0.2)
for a in list:
    try:
        if a['kCGWindowName'] == windowName:
            print "**** yippee *****"
            print "window found"
            print a
            found = True
            break
    except:
        pass
    if found == True:
        break
    print "NOT FOUND", count
    count+=1

print datetime.datetime.now()

这篇关于什么是Mac上python 2.7中win32gui的替代方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 13:35