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.

Tkinter filedialog.askdirectory() freezing when importing pywinauto

See original GitHub issue

Hi,

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:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
airelilcommented, Dec 18, 2018

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

import pywinauto
import tkinter.filedialog
tkinter.filedialog.askdirectory()

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 is askdirectory call 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:

import sys
sys.coinit_flags = 2  # COINIT_APARTMENTTHREADED

import pywinauto
import tkinter.filedialog
tkinter.filedialog.askdirectory()
1reaction
ilykoscommented, Apr 27, 2021

This seems to be a pyglet issue. I am using Pyglet 1.5.15 on python 3.7. the askopenfilename() invokation causes the program to freeze.

My suboptimal solution to this was to askdirectory() before importing pyglet.

Read more comments on GitHub >

github_iconTop 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 >

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