Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Lib/tkinter/filedialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ def _fixoptions(self):
pass

def _fixresult(self, widget, result):
# gh-103878: empty string from Tcl may have non-string type
if result in ((), b''):
result = ''

if result:
# keep directory and filename until next time
# convert Tcl path objects to strings
Expand All @@ -335,6 +339,10 @@ class Open(_Dialog):
command = "tk_getOpenFile"

def _fixresult(self, widget, result):
# gh-103878: empty string from Tcl may have non-string type
if result in ((), b''):
result = ''

if isinstance(result, tuple):
# multiple results:
result = tuple([getattr(r, "string", r) for r in result])
Expand Down Expand Up @@ -362,6 +370,10 @@ class Directory(commondialog.Dialog):
command = "tk_chooseDirectory"

def _fixresult(self, widget, result):
# gh-103878: empty string from Tcl may have non-string type
if result in ((), b''):
result = ''

if result:
# convert Tcl path objects to strings
try:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Ensure Tkinter file dialogs return ``""`` rather than ``()`` or ``b""``
when canceled.