0

I'm trying to set up some Python scripts to do some file manipulation and I was trying tkinter after some googling of libraries to use.

The following only half works:

from tkinter import filedialog

file_path = filedialog.askopenfilename() 
print(file_path)
export_folder = filedialog.askdirectory()
print(export_folder)

When I run this code in VSCode, the askopenfilename() works properly, but when it moves on to the askdirectory() it just seems to hang and I end up having to kill the script after some time.

However, when I run the exact same code using IDLE, it does both things just fine.

Has anyone else had this issue with VSCode and if so, how did you fix it?

7
  • What version of VS Code are you using? I was able to run this without issue. For completeness, I tested selecting something or canceling for each dialog. Commented May 22 at 19:13
  • Here's the info from the about window in VS Code: Version: 1.100.2 (user setup) Commit: 848b80aeb52026648a8ff9f7c45a9b0a80641e2e Date: 2025-05-14T21:47:40.416Z Electron: 34.5.1 ElectronBuildId: 11369351 Chromium: 132.0.6834.210 Node.js: 20.19.0 V8: 13.2.152.41-electron.0 OS: Windows_NT x64 10.0.22631 Commented May 22 at 19:27
  • 1
    Have you tried rolling back to an older version of VS Code? I ran this on Windows in both v1.83 and 1.98 without issues (running Python 3.11.3 and 3.13.2 respectively). What version of Python are you using? Commented May 22 at 19:32
  • 2
    IDLE and VSCode are tools only to create code. You don't need it to run it when all code is finished, and other people also don't need IDLE and VSCode to use your script - so more important is how it works without IDLE and VSCode Commented May 22 at 19:48
  • 1
    You can try creating the root window explicitly and making it topmost and hidden (withdraw) before calling askopenfilename(). Commented May 23 at 1:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.