4

Python 3.7.1 // Tk version 8.6 // pywinauto-0.6.8 // PyCharm Community Edition 2020.1 x64

The objective is to have the button send keys to the window in the background. Issue appears due to the presence of pywinauto. If inactive:

from tkinter import *
# from pywinauto.keyboard import send_keys

def left_click(event):
    # send_keys('%{TAB}')
    # send_keys('{{}ENTER{}}')
    print("hello")

root = Tk()

label1 = Label(root, text="Other")
label1.grid(row=0, sticky=E)
bt1_label1 = Button(root, text="Button_1", bg="red")
bt1_label1.grid(row=0, column=1)
bt1_label1.bind("<Button-1>", left_click)

root.mainloop()

Return when manually closing the tkinter window is:

hello

Process finished with exit code 0

If pywinauto is active (uncommented):

from tkinter import *
from pywinauto.keyboard import send_keys

def left_click(event):
    # send_keys('%{TAB}')
    # send_keys('{{}ENTER{}}')
    print("hello")

root = Tk()

label1 = Label(root, text="Other")
label1.grid(row=0, sticky=E)
bt1_label1 = Button(root, text="Button_1", bg="red")
bt1_label1.grid(row=0, column=1)
bt1_label1.bind("<Button-1>", left_click)

root.mainloop()

Return when manually closing the tkinter window is:

hello

Process finished with exit code -1073740771 (0xC000041D)

Any ideas why this happens?

AMC
  • 41
  • 2
  • Try to reverse the`import` order. – stovfl Apr 23 '20 at 08:30
  • Reversing the import order did not work. As it stands in that code, `pywinauto` isn't even used when it's uncommented, but that is enough to change the return code somehow. – AMC Apr 23 '20 at 11:49
  • Relevant [pywinauto/issues/894](https://github.com/pywinauto/pywinauto/issues/894) – stovfl Apr 23 '20 at 12:03
  • Can you try to uninstall `comtypes` and try again with `import pywinauto`? – Vasily Ryabov Apr 23 '20 at 12:08
  • It doesn't work at all without `comtypes`. At this point, I suspect it's an incompatibility between the Python version and Pywinauto. – AMC Apr 25 '20 at 03:46
  • Can any of you actually run my second code without the error? If so, please let me know on what versions, so I can try to duplicate. – AMC Apr 26 '20 at 07:37

0 Answers0