Fix/workaround for path separators on Windows

On Windows, many file dialogs return paths with "/" as folder separators, instead of "\". This is a simple workaround.
This commit is contained in:
Ricardo Mendonça Ferreira 2018-11-03 23:24:43 -03:00 committed by GitHub
parent 0652791b76
commit fd0b48e5d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

View File

@ -1316,6 +1316,8 @@ class Button(Element):
folder_name = tk.filedialog.askdirectory(initialdir=self.InitialFolder) # show the 'get folder' dialog box
if folder_name != '':
try:
if sys.platform == 'win32':
folder_name = folder_name.replace("/", "\\")
strvar.set(folder_name)
self.TKStringVar.set(folder_name)
except:
@ -1326,6 +1328,8 @@ class Button(Element):
else:
file_name = tk.filedialog.askopenfilename(filetypes=filetypes, initialdir=self.InitialFolder) # show the 'get file' dialog box
if file_name != '':
if sys.platform == 'win32':
file_name = file_name.replace("/", "\\")
strvar.set(file_name)
self.TKStringVar.set(file_name)
elif self.BType == BUTTON_TYPE_COLOR_CHOOSER:
@ -1340,6 +1344,8 @@ class Button(Element):
file_name = tk.filedialog.askopenfilenames(filetypes=filetypes, initialdir=self.InitialFolder)
if file_name != '':
file_name = ';'.join(file_name)
if sys.platform == 'win32':
file_name = file_name.replace("/", "\\")
strvar.set(file_name)
self.TKStringVar.set(file_name)
elif self.BType == BUTTON_TYPE_SAVEAS_FILE:
@ -1349,6 +1355,8 @@ class Button(Element):
file_name = tk.filedialog.asksaveasfilename(filetypes=filetypes,
initialdir=self.InitialFolder) # show the 'get file' dialog box
if file_name != '':
if sys.platform == 'win32':
file_name = file_name.replace("/", "\\")
strvar.set(file_name)
self.TKStringVar.set(file_name)
elif self.BType == BUTTON_TYPE_CLOSES_WIN: # this is a return type button so GET RESULTS and destroy window