Python File Manager, Treeview,scrollbar,__python

Source: Internet
Author: User
Import tkinter Import TKINTER.TTK import OS class treewindows:def __init__ (self): Self.win=tkinter. Tk () Self.tree=tkinter.ttk.treeview (self.win,height=500) #树状 Self.ysb=tkinter.ttk.scrollbar (Self.win,orien t= "Vertical", Command=self.tree.yview ()) #y滚动条 SELF.XSB = Tkinter.ttk.Scrollbar (Self.win, orient= "Horizontal", comm And=self.tree.xview ()) #x滚动条 self.tree.configure (yscroll=self.ysb.set,xscroll=self.xsb.set) #y滚动条关联 self.t Ree.grid (row=0,column=0) self.tree.heading ("#0", text= "Path", anchor= "W") #初始化头部, head west near western Self.tree.bind ("<<TreeviewSelect>>", Self.gosel) #事件 (checked) bind filepath= "C:\\aa\\desktop" #路径 root=self.tree.in SERT ("", "End", Text=filepath,open=true) #插入一个节点 self.loadtree (Root,filepath) #递归 self.e=tkinter. Stringvar () Self.entry=tkinter. Entry (SELF.WIN,TEXTVARIABLE=SELF.E) self.e.set ("Please select File") Self.entry.grid (row=0, column=2) SELF.YSB . gRID (row=0,column=1,sticky= "ns") Self.xsb.grid (row=1, column=0,sticky= "ew") Self.win.grid () #表格展示 def Loadtree (Self,parent,rootpath): For Path in Os.listdir (RootPath): #遍历当前目录 abspath=os.path.join (roo Tpath,path) #连接成绝对路径 Oid=self.tree.insert (parent, ' end ', text=abspath,open=false) #插入树枝 if os.path.is Dir (abspath): Self.loadtree (Oid,abspath) #递归回去 def gosel (self,event): Self.select=event.wi
            Dget.selection () #获取所选的项 (possibly multiple, so for loop) for IDX in Self.select:print (Self.tree.item (IDX) ["text"]) Self.e.set (Self.tree.item (IDX) ["text"]) def Show (self): Self.win.mainloop () mytree=treewindows (
 ) Mytree.show ()

Related Article

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.