Tkinter filedialog.askdirectory() freezing when importing pywinauto
See original GitHub issueHi,
I’ve logged this in the Python issue tracker already, but I’ve been told to follow up with you guys and see if it’s something that can be fixed on your end.
https://bugs.python.org/issue34029
Essentially, when pywinauto is imported, the tkinter.filedialog.askdirectory() function freezes the application and doesn’t open the askdirectory dialog.
From the bug:
Debugging a bit, the hang happens in Lib/tkinter/commondialog.py, line 43:
s = w.tk.call(self.command, *w._options(self.options))
The value of self.command is ‘tk_chooseDirectory’, and w._options(self.options) just gives an empty tuple, so the actual call is:
s = w.tk.call('tk_chooseDirectory', ())
This means that the hang is within w.tk.call().
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:9 (4 by maintainers)
Top Results From Across the Web
tkinter freezing with pywinauto import - Stack Overflow
If I comment out the pywinauto import, askdirectory works just fine. No freezing, the window pops up as expected.
Read more >Issue 34029: tkinter.filedialog.askdirectory() crashing before ...
I managed to track it down to the import of pywinauto to the application. All other filedialogs seem to work, it's only askdirectory...
Read more >[issue34029] tkinter.filedialog.askdirectory() crashing before ...
List: python-bugs-list Subject: [issue34029] tkinter.filedialog.askdirectory() crashing before dialog opens when importing pywinauto From: Tal Einat <report ...
Read more >[Example code]-tkinter freezing with pywinauto import
My python gui (tkinter) is freezing when I click a button that runs: filename = filedialog.askdirectory() This only happens when I have from...
Read more >Python Tkinter is freezing my mac : r/learnpython - Reddit
This is my tkinter code: import tkinter as tk. from tkinter import filedialog. root = tk.Tk(). root.withdraw(). file_path = filedialog.askopenfilename().
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Hi @rsteel1, finally we got the chance to look into this issue. I was able to reproduce the reported problem on my Win8.1 64-bit machine with 64-bit Python 3.6 using the code below
Since this involves windows file dialogs I suspected that the origin of the problem is incompatible COM threading model. By default, pywinauto sets up the Multithreading COM model (MTA) on init if no other mode was defined prior to import of pywinauto or specified explicitly through
sys.coinit_flags. My guess isaskdirectorycall uses “appartment threaded model” that is incompatible with MTA mode that was defined during pywinauto import. So to solve the problem we should specify the appropriate threading model explicitly as in the example below:This seems to be a pyglet issue. I am using
Pyglet1.5.15 on python 3.7. theaskopenfilename()invokation causes the program to freeze.My suboptimal solution to this was to
askdirectory()before importingpyglet.