码迷,mamicode.com
首页 > 其他好文 > 详细

tkinter学习06

时间:2018-11-03 01:50:48      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:func   widget   roo   sid   dir   values   inf   import   评价   

技术分享图片
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

 技术分享图片

 

技术分享图片

 

tkinter学习06

标签:func   widget   roo   sid   dir   values   inf   import   评价   

原文地址:https://www.cnblogs.com/Mengchangxin/p/9898824.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!