如何在 python IDLE 编辑器中使用 pywinauto set_text?

How to use pywinauto to set_text in python IDLE editor?

我想用 pywinauto 控制 python IDLE。

我可以启动 IDLE,但无法输入文本。

这是我的代码:

import pywinauto
app = pywinauto.application.Application(backend="uia").start(r"C:\Python37\pythonw.exe C:\Python37\Lib\idlelib\idle.pyw")
app2 = pywinauto.application.Application().connect(process=app.process)

我尝试使用 app2.Property.print_control_identifiers() 但它 returns:

Traceback (most recent call last):
  File "C:\Python37\lib\site-packages\pywinauto\application.py", line 256, in __resolve_control
    criteria)
  File "C:\Python37\lib\site-packages\pywinauto\timings.py", line 458, in wait_until_passes
    raise err

pywinauto.timings.TimeoutError

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
    app2.Property.print_control_identifiers()
  File "C:\Python37\lib\site-packages\pywinauto\application.py", line 595, in print_control_identifiers
    this_ctrl = self.__resolve_control(self.criteria)[-1]
  File "C:\Python37\lib\site-packages\pywinauto\application.py", line 259, in __resolve_control
    raise e.original_exception
  File "C:\Python37\lib\site-packages\pywinauto\timings.py", line 436, in wait_until_passes
    func_val = func(*args, **kwargs)
  File "C:\Python37\lib\site-packages\pywinauto\application.py", line 201, in __get_ctrl
    dialog = self.backend.generic_wrapper_class(findwindows.find_element(**criteria[0]))
  File "C:\Python37\lib\site-packages\pywinauto\findwindows.py", line 84, in find_element
    elements = find_elements(**kwargs)
  File "C:\Python37\lib\site-packages\pywinauto\findwindows.py", line 303, in find_elements
    elements = findbestmatch.find_best_control_matches(best_match, wrapped_elems)
  File "C:\Python37\lib\site-packages\pywinauto\findbestmatch.py", line 533, in find_best_control_matches
    raise MatchError(items = name_control_map.keys(), tofind = search_text)
pywinauto.findbestmatch.MatchError: Could not find 'Property' in 'dict_keys(['*Python 3.7.2 Shell*TkTopLevel', '*Python 3.7.2 Shell*', 'TkTopLevel'])'

如何解决问题?

谢谢。

我怀疑你是否可以做任何你想做的事。 pywinauto site 说 "pywinauto is a set of python modules to automate the Microsoft Windows GUI. At its simplest it allows you to send mouse and keyboard actions to windows dialogs and controls." IDLE 使用 tkinter,它使用 tcl/tk gui 框架。虽然最终使用 Windows 图形,但它可能不在 pywinauto 访问的级别。

app = pywinauto.application.Application(backend="uia").start(r"C:\Python37\pythonw.exe C:\Python37\Lib\idlelib\idle.pyw")
app2 = pywinauto.application.Application().connect(process=app.process)
app3 = app2.top_window()
app3.print_control_identifiers()

您可以使用最适合 windows GUI 自动化的 pyautogui

我使用 pyautogui 将 RDP 连接转换为自动化

import pyautogui
import time
import os

os.system("C:\Users\Administrator\Desktop\RDC.bat")
print(pyautogui.position())
time.sleep(5)

pyautogui.click(490,404)
pyautogui.typewrite("Bitwise3")
pyautogui.typewrite(["Enter"])