Display file names in Tkinter Listbox
John McMonagle
jmcmonagle at NO.SPAM.velseis.com.au
Thu May 20 18:02:30 EDT 2010
sit at home.com wrote:
> I have made the modifications and it does print inside the listbox,
> however they are all printed on the same line.
>
Sorry, I didn't realize askopenfilenames returned the filenames as a
whitespace separated string, on my system they are returned as a tuple
of strings.
> My files are named Name.0 Name.1 Name.2 Name.3 etc so I would like
> them to be printed sorted on a separate line. When I did a
> type(fileNames) it showed me that it was in unicode and printed
> character per line, so I tried it this way
>
> listFileNames = str(fileNames).split(' ')
> for fileName in listFileNames:
> self.lbox.insert(0, fileName)
>
> it works but does not print sorted.
>
> it prints
>
> name.2
> name.1
> name.0
> name.3
>
>
You obviously need to sort the list before you loop over the items and
add them to your listbox.
listFileNames = sorted(str(filenames).split()
Regards,
John
More information about the Python-list
mailing list