From: John on 10 Aug 2010 00:53 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. 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): L.insert(END, filename) mainloop() Is there a way to list folders with images? Any suggestions or help how to proced would be appreciated. Thank you
From: Chris Rebert on 10 Aug 2010 01:07 On Mon, Aug 9, 2010 at 9:53 PM, <John(a)mail.python.org> 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. os.path.isdir() tests a path for directory-ness. Check out the os.path std lib module generally: http://docs.python.org/library/os.path.html Cheers, Chris -- http://blog.rebertia.com
From: Eric Brunel on 10 Aug 2010 04:40 In article <d4m1661blus6baj1lrd37j5vk4dau350jj(a)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!
From: John on 10 Aug 2010 10:58 On Tue, 10 Aug 2010 10:40:53 +0200, Eric Brunel <eric.brunel(a)pragmadev.com> wrote: >In article <d4m1661blus6baj1lrd37j5vk4dau350jj(a)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! Thank you both for the suggestions. Have you ever tried to make one?
From: Jeff Hobbs on 10 Aug 2010 12:20
On Aug 9, 9:53 pm, 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. Filter with os.path.isdir() > Is there a way to list folders with images? > Any suggestions or help how to proced would be appreciated. If you are using a Tkinter with Ttk (Tk 8.5), then use the treeview widget: http://docs.activestate.com/activepython/3.1/python/library/tkinter.ttk.html For more advanced needs, there is a Tk extension called tktreectrl that does some very cool views and has lots of controls: http://tktreectrl.sourceforge.net/ Jeff |