Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tkinter.filedialog.askdirectory() hangs if the directory name has right trailing blanks #126839

Open
Madpentiste opened this issue Nov 14, 2024 · 1 comment
Labels
stdlib Python modules in the Lib dir topic-tkinter type-bug An unexpected behavior, bug, or error

Comments

@Madpentiste
Copy link

Madpentiste commented Nov 14, 2024

Bug report

Bug description:

# Add a code block here, if required

from tkinter import filedialog as FD
from tkinter import *

Racine = Tk()
Racine.withdraw() 
chosen_dir = FD.askdirectory(parent=Racine)
print("Chosen directory :", chosen_dir)
Racine.destroy()

# more python here, using the variable chosen_dir

Giving names to directories with right trailing blanks sometime happens. OS like Linux keep them as they are, untrimmed.
Directories with such names cannot be chosen with a python program using tkinter.filedialog.askdirectory() because the python program hangs with the filedialog window open; only the Cancel button or the close-window's widget will close it, with a wrong value for chosen_rep.

The most simple workaround is to remove right-trailing blanks from directory names before starting the python program involving a tkinter.filedialog.askdirectory() function call; this is a tedious task since these blanks are difficult to spot. In my case, it took me time to figure out why my program would work fine most of the times (directories with no blank at the end of their names), but would hang in some cases ; I finally found out that the trailing blanks in the directory name were the issue.

CPython versions tested on:

3.10

Operating systems tested on:

Linux

@Madpentiste Madpentiste added the type-bug An unexpected behavior, bug, or error label Nov 14, 2024
@picnixz picnixz added stdlib Python modules in the Lib dir topic-tkinter labels Nov 14, 2024
@serhiy-storchaka
Copy link
Member

What is the Tk version?

I tested on Linux (Tk 8.6.12). Pressing button OK does not work first time, but pressing it again closes the dialog Window and returns the path with trimmed spaces. The same behavior is in pure Tcl/Tk.

puts "([tk_chooseDirectory -parent .])"

So this is not Python issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir topic-tkinter type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants