I hope someone can help.
I have a function that opens can open multiple civ files
def datasetUpload():
global file_path
file_path = filedialog.askopenfilename(initialdir='/', filetypes=(('CSV files', '*.csv'),), multiple=True)
for file in file_path:
pathlabel.config(text=file '\n')
What I'd like to achieve is to print on the main window all paths of the files that the user has chosen. This code unfortunately prints out only the last file in the file_path list. I have tried everything, I created empty list, appended all the files there but then the file paths weren't printed user friendly. It included {} for each file. What I'd like to achieve is something that can be achieve with print statement:
def datasetUpload():
global file_path
file_path = filedialog.askopenfilename(initialdir='/', filetypes=(('CSV files', '*.csv'),), multiple=True)
for file in file_path:
print(file)
This code obviously prints everything nicely into the console but I'd like to print this out to the window for the user, so the user knows which files were selected. I hope it makes sense and I hope there is a way how to do it. I also tried to do it with Text widget in tkinter but that obviously can be edited by the user and if I change state attribute to disabled then nothing gets printed at all. Many thanks for any suggestions.
CodePudding user response:
You need to join the selected paths into a string and then update the label text with the joined string:
def datasetUpload():
global file_path
file_path = filedialog.askopenfilename(initialdir='/', filetypes=(('CSV files', '*.csv'),), multiple=True)
pathlabel.config(text='\n'.join(file_path))