【发布时间】:2021-12-24 19:45:02
【问题描述】:
我正在尝试自动化一些 Windows 任务,我得到了所有打开的窗口的数据框,然后我添加了一些列以便在继续自动化之前进行一些验证。
从set_focus() 函数激活窗口后,我根本无法调整任何窗口的大小,只是什么都没有发生。
我已经尝试过使用win32gui 解决方案:
current = win32gui.GetForegroundWindow()
win32gui.MoveWindow(current, 0, 0, 100, 100, True)
我也尝试将pygetwindow 函数用于resizeTo 或size,但也没有任何反应。
如果我运行以下命令app.move_window(x=None, y=None, width=100, height=100, repaint=True):AttributeError: 'UIAWrapper' object has no attribute 'move_window'。
我的代码:
from pywinauto import Desktop
import pandas as pd
windows = Desktop(backend="uia").windows()
window = [w.window_text() for w in windows]
# Create a dataframe in order to store the windows needed
df_windows = pd.DataFrame(window, columns =['WebBrowser'])
# Filter dataframe only to show all windows from Brave web browser
df_windows = df_windows.loc[df_windows['WebBrowser'].str.contains("Brave:", case=False)]
# Add column profile from Brave
df_windows['Profile'] = df_windows['WebBrowser'].str.split(':').str[1].str.strip()
# Add column window open from Brave
df_windows['Window'] = df_windows['WebBrowser'].str.split(':').str[0].str.strip()
# Add column about the website open from Brave
df_windows['Website'] = df_windows['Window'].str.replace(" - Brave", "").str.strip()
# Filter dataframe only to show all bombcrypto game window
df_windows = df_windows.loc[df_windows['Website'] == 'GuilhermeMatheus']
print(df_windows)
for x in df_windows['WebBrowser']:
print(x)
app = Desktop(backend="uia").windows(title=x)[0]
app.set_focus()
app.move_window(x=None, y=None, width=100, height=100, repaint=True)
set_focus() 之后如何调整活动窗口的大小?
[编辑]
按照@Vasily Ryabov 的提示,我下载了Windows SDK 以安装具有Inspect.exe 的功能,还遵循pywinauto 的文档Getting Start 主题和Accessibility tools - Inspect 提供的文档我是能够通过 Inspect 找到我的应用程序,Resize 选项可作为以下证据:
所以我尝试了以下命令:
1º:
app.iface_transform.Resize(200, 600)
错误:
app.iface_transform.Resize(200, 600)
_ctypes.COMError: (-2146233079, None, (None, None, None, 0, None))
2º:
app.Resize(200, 600)
错误:
AttributeError: 'UIAWrapper' object has no attribute 'Resize'
3º:
app.wrapper_object.Resize(200, 600)
错误:AttributeError: 'UIAWrapper' object has no attribute 'wrapper_object'
【问题讨论】:
标签: python pywin32 pywinauto win32gui