I'm populating a tkinter listbox with files from a directory. The names of the files all start with a number from 01 - n. When I view the files in the directory they appear in numerical order. However, when I load the files into a listbox they aren't ordered numerically. I can change the leading numbers around, but the same files will always appear in the same spot.
I'm just using simplified item names to keep things simple with this example. It still shows that they're not being sorted alphabetically nor numerically.
The list should appear as the following in my listbox
01. itemA
02. itemB
03. itemC
04. itemD
But it appears as:
01. itemA
04. itemD
02. itemB
03. itemC
I can change the leading numbers around, but the files will always populate in the same order (by name, not number). The strange thing is, it's not even alphabetical order.
I've used this
i = 0
for filename in os.listdir(directory):
fileList.insert(i, filename)
i = i + 1
And this
for filename in os.listdir(directory):
fileList.insert(END, filename)
Both result in the same thing.