AttributeError: module 'win32gui' has no attribute 'GetWindowThreadProcessId'
时间: 2023-06-23 19:43:39 浏览: 739
这个错误通常是因为没有正确安装 `pywin32` 库导致的。请尝试使用以下命令安装 `pywin32` 库:
```
pip install pywin32
```
如果您已经安装了该库,请确保您的 `pywin32` 版本与您的 Python 版本兼容。您可以在以下网址下载适合您 Python 版本的 `pywin32` 版本:https://github.com/mhammond/pywin32/releases
如果您已经安装了正确版本的 `pywin32` 库但仍然遇到此错误,请尝试使用以下代码:
```python
from win32process import GetWindowThreadProcessId
def get_hwnds_for_pid(pid):
def callback(hwnd, hwnds):
if win32gui.IsWindowVisible(hwnd) and win32gui.IsWindowEnabled(hwnd):
_, found_pid = GetWindowThreadProcessId(hwnd)
if found_pid == pid:
hwnds.append(hwnd)
return True
hwnds = []
win32gui.EnumWindows(callback, hwnds)
return hwnds
```
这样应该可以解决 `AttributeError: module 'win32gui' has no attribute 'GetWindowThreadProcessId'` 错误。