Display file names in Tkinter Listbox
sit at home.com
sit at home.com
Thu May 20 19:26:41 EDT 2010
On Fri, 21 May 2010 08:02:30 +1000, John McMonagle
<jmcmonagle at NO.SPAM.velseis.com.au> wrote:
>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
Thank you, it worked
More information about the Python-list
mailing list