tkinter学习06

import tkinter
import os
from treeWindows import TreeWindows
from infoWindows import InfoWindows
import tkinter.filedialog as dir

win=tkinter.Tk()
win.title("植物打大战")
win.geometry("900x400+200+50")
path=r"C:\Users\admin\Desktop\23家上报"
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 tkinter
from tkinter import ttk
import os

class 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)

        #滚动条
        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)

        #绑定事件
        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': '2015-2017年设计质量评价.xlsx', 'image': '',
             # 'values': ['C:Users\x07dminDesktop\x13家上报\x815-2017年设计质量评价.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 tkinter
from tkinter import ttk
import os

class 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

 

 

 

posted @ 2018-11-02 22:24  巨兽~墨菲特  阅读(201)  评论(0编辑  收藏  举报