File Manager in Tkinter

Eric Brunel eric.brunel at pragmadev.com
Tue Aug 10 04:40:53 EDT 2010


In article <d4m1661blus6baj1lrd37j5vk4dau350jj at 4ax.com>, John wrote:

> As a learning exercise in Tkinter I htought about making a very simple
> and basic file manager for my own use. I tried searching google for
> any sample project and could not find anything. Not exactly  sure how
> to start I tought I could ask here? 
> 
> I thought about making two listboxes one to list folders only the
> other files inside. I tried to make one listbox first but did not know
> how to list folders only.

You just have to filter them explicitely by using os.path.isdir on each 
file name.

> from Tkinter import *
> import os
> path = "D:\\"
> 
> 
> s = Scrollbar()
> L = Listbox()
> 
> s.pack(side=RIGHT, fill=Y)
> L.pack(side=LEFT, fill=Y)
> 
> s.config(command=L.yview)
> L.config(yscrollcommand=s.set)
> 
> for filename in os.listdir(path):

Add here:
   if os.path.isdir(os.path.join(path, filename)):
>   L.insert(END, filename)
> 
> mainloop()
> 
> 
> 
> Is there a way to list folders with images?

AFAIK, not with a Listbox. You can do it with a Canvas, but it's much 
more complicated than using a Listbox, so maybe you should try to make 
your Listbox-only version works first.

> Any suggestions or help how to proced would be appreciated.
> 
> Thank you

Good luck!



More information about the Python-list mailing list