我正在寻找一种设置事件窗口的方法。我找到的唯一解决方案已经过时。它们包括像 pywinauto
这样的模块,但它的 focus()
函数不起作用。
我需要一些可以快速切换/激活另一个窗口的东西。
我尝试了下面的代码,但它不起作用,因为它说 object has no attribute 'focus'
import pygetwindow as gw
win = gw.getWindowsWithTitle('Photoshop')[0]
win.focus()
我正在使用 Windows 8
最佳答案
我认为您所追求的对象方法是activate
:
>>> help(win.activate)
Help on method activate in module
pygetwindow._pygetwindow_win:
activate() method of
pygetwindow._pygetwindow_win.Win32Window instance
Activate this window and make it the foreground window.
因此按如下方式更改您的代码应该可行。
import pygetwindow as gw
win = gw.getWindowsWithTitle('Photoshop')[0]
win.activate()
关于python - 更改事件窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58333255/