question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pywinauto crashes with tkinter on Python 3.7 on exit

See original GitHub issue

Simply importing pywinauto and tkinter together will crash Python 3.7 post execution

Expected Behavior

Not get any “Python has stopped working” crash message after Python script has executed.

Actual Behavior

After execution, Python should be able to exit gracefully without a crash message.

Steps to Reproduce the Problem

  1. import tkinter
  2. import pywinauto
  3. create a Tk() instance
  4. quit Tk instance
  5. Python script will exit but a crash message will be shown

Short Example of Code to Demonstrate the Problem

import tkinter as tk
import pywinauto as pyw
root = tk.Tk()

Specifications

  • Pywinauto version: 0.6.7
  • Python version and bitness: 3.7-32
  • Platform and OS: Windows 10 64 bit

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
fizban99commented, Sep 2, 2021

Just wanted to add some additional information. In my case, I have Python 3.7.6 on Windows 10 and I was experiencing the same issue. The workaround of launching the script with pythonw did not work. The only workaround I found was using a hard exit after mainloop:

import os
import tkinter as tk
import win32ui
root = tk.Tk()
root.mainloop()
os._exit(0)
1reaction
np-8commented, Nov 22, 2020

I tried to reproduce the problem with the abovementioned

import win32ui
import tkinter as tk
root = tk.Tk()
root.mainloop()

but was unable to get any errors. I tested even with the same exact Python version, and tried multiple pywin32 versions. Tested versions, without any error:

  • Python 3.8.6 32-bit (venv), + pywin 300
  • Python 3.7.9 64-bit, + pywin 300
  • Python 3.7.7 32-bit, + pywin 300, 227, 226, 225, 224, 223 and 222

This is strange since before at least with Python 3.7.7 32-bit + pywin 222-227 (some of them) I last time could reproduce the error. Also this did not produce the error (Python 3.7.7 32-bit + pywin 227 + pywinauto 0.6.8):

import tkinter as tk
import pywinauto as pyw
root = tk.Tk()
root.mainloop()

Some hypothesis for the reason:

(1) The pywin pywin32_postinstall.py had one error on -remove : (Failed to unregister Pythonwin: [WinError 5] Access is denied), even with admin rights, but the -install and dll copying was working without errors. This could in theory affect testing of multiple pywin32 versions, but I think that’s very small change. (2) I have now new laptop and probably also newer Windows 10 build. (1909, OS Build 18363.1139). Maybe that could affect?

Maybe there could be some other reasons, too, but seems that this will be difficult to hunt down. This as a note if anyone starts debugging the issue some day.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Combining Tkinter and win32ui makes Python crash on exit
A workaround is to invoke the Tkinter-win32UI app with pythonw. Python doesn't crash. Tested with Python 3.6.3 on Win 10.
Read more >
Python Has Stopped Working When Importing Pywinauto ...
Hi I've logged this in the Python issue tracker already but I've been told pywinauto crashes with tkinter on Python 3.7 on exit...
Read more >
List of issues - Python tracker
Severity ID GH Creation Activ... 2018‑06‑29.15:48:52 duplicate 2018‑06‑29.15:48:52 duplicate normal 34000 78181 53 months ago 7 mo... 2018‑06‑29.16:09:13 fixed 2018‑06‑29.16:09:13 fixed
Read more >
Pygame window wont move or close after using tkinter
How to close a window using pywinauto which does not have "File->exit" in menu? ... How to open and close another window with...
Read more >
PyInstaller Documentation - Read the Docs
PyInstaller supports Python 3.7 and newer, and correctly ... The _MEIxxxxxx folder is not removed if the program crashes or is killed (kill...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found