GUI file Traversal System (listdir.py) to display Chinese catalog file version

Source: Internet
Author: User

This application is a directory tree traversal tool. It starts with the current directory and provides the file list functionality. Double-clicking any other directory in the list will let the tool turn to the new directory and replace the existing file list with the list of files in the new directory.

Run:

#coding: Gbkimport osfrom time import sleepfrom Tkinter import *class dirlist (object): Def __init__ (Self,initdir=none): Self.top = Tk () Self.label = label (self.top,text= ' Directory Lister v1.1 ') self.label.pack () se LF.CWD = Stringvar (self.top) Self.dir1 = Label (self.top,fg= ' Blue ', font= (' Helvetica ', ' bold ')) SELF.DIR1.PA CK () Self.dirfm = Frame (self.top) SELF.DIRSB = Scrollbar (SELF.DIRFM) self.dirsb.pack (side=right,fill=        Y) Self.dirs = Listbox (self.dirfm,height=15, Width=50,yscrollcommand=self.dirsb.set) Self.dirs.bind (' <Double-1> ', Self.setdirandgo) self.dirsb.config (Command=self.dirs.yview) self.dirs . Pack (Side=left,fill=both) self.dirfm.pack () Self.dirn = Entry (self.top,width=50, t EXTVARIABLE=SELF.CWD) self.dirn.bind (' <Return> ', Self.dols) self.dirn.pack () SELF.BFM = Frame (SE Lf.top) SELF.CLR= Button (self.bfm,text= ' Clear ', Command=self.clrdir, Activeforeground= ' W                         Hite ', activebackground= ' blue ') Self.ls = Button (self.bfm,text= ' List Directory ', Command=self.dols, activeforeground= ' white ', Activebackgrou                           nd= ' green ') Self.quit = Button (self.bfm,text= ' Quit ', Command=self.top.quit,        activeforeground= ' White ', activebackground= ' Red ') Self.clr.pack (side=left) Self.ls.pack (Side=left) self.quit.pack (side=left) self.bfm.pack () if INITDIR:SELF.C Wd.set (Os.curdir) self.dols () def clrdir (Self,ev=none): Self.cwd.set (") def Setdirandgo (self,ev=n One): Self.last = Self.cwd.get () self.dirs.config (selectbackground= ' red ') check = Self.dirs.get (self.    Dirs.curselection ())    If not Check:check = Os.curdir self.cwd.set (check) self.dols () def dols (Self,ev=none): Error = ' Tdir = Self.cwd.get () if not tdir:tdir = Os.curdir if not os.path.exists ( Tdir): Error = Tdir + ': No such file ' Elif not Os.path.isdir (tdir): Error = Tdir + ': not a Directory ' if Error:self.cwd.set (Error) Self.top.update () sleep (2) if                Not (hasattr (self, ' last ') and self.last): Self.last = Os.curdir Self.cwd.set (self.last)        Self.dirs.config (selectbackground= ' Lightskyblue ') self.top.update () return Self.cwd.set (' Fetching DIRECTORY CONTENTS ... ') self.top.update () Dirlist = Os.listdir (tdir) dirlist.        Sort () Os.chdir (Tdir) self.dir1.config (Text=unicode (OS.GETCWD (), ' GBK ')) Self.dirs.delete (0,end) Self.dirs.insert (End,oS.curdir) Self.dirs.insert (end,os.pardir) for eachfile in Dirlist:try:eachfile=u Nicode (Eachfile, ' GBK ') Except:pass Self.dirs.insert (end,eachfile) SELF.CW D.set (Os.curdir) self.dirs.config (selectbackground= ' Lightskyblue ') def main (): D=dirlist (Os.curdir) Mainlo     OP () If __name__== ' __main__ ': Main ()

GUI file Traversal System (listdir.py) to display Chinese catalog file version

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.