Tkinter learning 06

Source: Internet
Author: User
Tags osclass
Import tkinterimport osfrom treewindows import treewindowsfrom infowindows import infowindowsimport tkinter. filedialog as dirwin = tkinter. TK () win. title ("fighting plants") win. geometry ("900x400 + 200 + 50") Path = r "C: \ Users \ admin \ Desktop \ 23 reporting" def open_dir (PATH): D = dir. directory () Path = D. show (initialdir = path) return path # print (open_dir (PATH) infowin = infowindows (WIN) treewin = treewindows (Win, path, infowin)
Man. py
Import tkinterfrom tkinter import ttkimport osclass treewindows (tkinter. frame): def _ init _ (self, Master, path, otherwin): Self. path = OS. path. abspath (PATH) frame = tkinter. frame (master) frame. grid (ROW = 0, column = 0, padx = 15, pady = 15) self. otherwin = otherwin self. tree = ttk. treeview (FRAME) self. tree. pack (side = tkinter. left, fill = tkinter. y) root = self. tree. insert ("", "end", text = self. getlastpath (self. path), open = true, values = (self. path) self. loadtrea (root, self. path) # scroll bar self. sy = tkinter. scrollbar (FRAME) self. sy. pack (side = tkinter. right, fill = tkinter. y) self. sy. config (command = self. tree. yview) self. tree. config (yscrollcommand = self. sy. set) # bind event self. tree. BIND ("<treeviewselect>", self. func) def func (self, event): Self. V = event. widget. selection () for SV in self. v: file = self. tree. item (SV) ["text"] print (File) self. otherwin. ev. set (File) # {'text': '2017-design quality evaluation .xlsx ', 'image': '', # 'values': ['C: users \ x07dmindesktop \ x13 reporting \ x815-design Quality Evaluation .xlsx '], 'open': 0, 'tags': ''} # apath = self. tree. item (SV) ["values"] [0] # print ("3", apath) def loadtrea (self, parent, parent_path): For file_name iN OS. listdir (parent_path): abs_path = OS. path. join (parent_path, file_name) treey = self. tree. insert (parent, "end", text = self. getlastpath (abs_path), values = (abs_path) If OS. path. isdir (abs_path): Self. loadtrea (treey, abs_path) def getlastpath (self, PATH): pathlist = OS. path. split (PATH) return pathlist [-1]
Treewindows. py
import tkinterfrom tkinter import ttkimport osclass InfoWindows(tkinter.Frame):    def __init__(self,master):        frame = tkinter.Frame(master)        frame.grid(row=0, column=1, padx=15, pady=15)        self.ev=tkinter.Variable()        self.entry=tkinter.Entry(frame,textvariable=self.ev)        self.entry.pack(side=tkinter.TOP,fill=tkinter.X, pady=8)        self.txt=tkinter.Text(frame)        self.txt.pack(fill=tkinter.BOTH)
Infowindows. py

 

 

 

Tkinter learning 06

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.