Merge pull request #652 from AltoRetrato/patch-1

Fix/workaround for path separators on Windows
This commit is contained in:
MikeTheWatchGuy 2018-11-04 09:51:21 -05:00 committed by GitHub
commit ae83663ba1
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