python / cpython

The Python programming language
https://www.python.org
Other
62.38k stars 29.96k forks source link

filedialog.askdirectory "Cancel" behaves differently under Linux and Windows (Wine) #103878

Open 4LT opened 1 year ago

4LT commented 1 year ago

Bug report

Native Linux binary and Windows executable (under Wine) have different behaviors for tkinter's filedialog.askdirectory. Clicking "Cancel" results in a return value of () (empty tuple) under Linux, and "" for the Windows executable.

Your environment

3.11

Arch Linux 6.2.9 natively AND under Wine 8.5

Linked PRs

ronaldoussoren commented 1 year ago

On macOS this returns "".

chrstphrchvz commented 1 year ago

The underlying Tcl/Tk command tk_chooseDirectory (as well as tk_getOpenFile and tk_getSaveFile) has implementations for each platform. From Tcl/Tk’s perspective, clicking “cancel” causes an empty string value to be returned regardless of platform. However incidental differences between these implementations are causing the returned empty string value to either be unshared and untyped on Win32 and Aqua, or highly shared and often having type (such as "list", since the empty string is the empty Tcl list) on X11. And in general Tkinter does not automatically convert a Tcl value to a Python string if it has a type (other than "string").

chrstphrchvz commented 1 year ago

A similar issue was already addressed for tkinter.colorchooser.Chooser: #48017

serhiy-storchaka commented 8 months ago

It would perhaps be more Pythonic to return None as a special value. Some other dialogs already return None if cancelled (for example askyesnocancel() and askstring()).