接着上文,自己动手实现一个专门的比较工具,现在还只是雏形,大体功能如下:
根据用户输入的关键字,遍历文件内容,并显示
支持文件FTP 功能
检查文件是否已文件名为内容开始
根据不同的关键字,生成一个summary 信息
两个文件夹的内容进行对比(待定)
涉及到的python知识点:
Label,Engry,Button,FileDialog,
StringVar
menu
pack
grid
对于新手而言,更多的熟悉各个组件的方法与属性。未完待续,欢迎高手指正!
-
# -*- coding: cp936 -*-
-
__author__ = 'kinfinger'
-
import os
-
import time
-
import tkFileDialog
-
import tkMessageBox
-
from Tkinter import *
-
-
-
class FileGuiChose(object):
-
def __init__(self,initdir=None,frame=None,showframe=None):
-
self.entryvar =StringVar()
-
self.showframe=showframe
-
self.glabel=Label(frame,text=u'你选择的目录为:')
-
self.gentry=Entry(frame,textvariable=self.entryvar)
-
self.gbutton=Button(frame,command=self.opendir,text=u'选取目录')
-
self.glabel.grid(row=0,column=0)
-
self.gentry.grid(row=0,column=1)
-
self.gbutton.grid(row =0,column=2)
-
-
def opendir(self):
-
self.dirname=tkFileDialog.askdirectory()
-
self.entryvar.set(self.dirname) # related to entry just for show
-
self.fguiShow=FileGuiShow(self.dirname,self.showframe)
-
class FileGuiShow():
-
def __init__(self,directory,showframe):
-
if directory:
-
self.dirlist=os.listdir(directory)
-
else:
-
showmessage=directory
-
self.messageBox=tkMessageBox.showinfo(showframe,message=showmessage)
-
self.showlist=Listbox(showframe,width=800,height=800)
-
self.showlist.pack()
-
for eachdir in self.dirlist:
-
self.showlist.insert(END,eachdir)
-
self.showlist.update()
-
class GuiMenu():
-
def hello(self):
-
pass
-
def File(self):
-
pass
-
def Edit(self):
-
pass
-
def View(self):
-
pass
-
def Help(self):
-
tkMessageBox.showinfo(self.root,'作者 kinfinger \n verion 1.0 \n Thank you ')
-
def __init__(self,rootmenu):
-
self.root=rootmenu
-
self.menubar=Menu(rootmenu)
-
rootmenu['menu']=self.menubar
-
self.menubar.add_command(label = 'File',command =self.File )
-
self.menubar.add_command(label = 'Edit',command =self.Edit )
-
self.menubar.add_command(label = 'View',command =self.View )
-
self.menubar.add_command(label = 'Help',command =self.Help)
-
def main():
-
root = Tk()
-
choseFrame=Frame(root,height=50,width=800,bg='red')
-
showFrame=Frame(root,height=800,width=800,bg='white')
-
choseFrame.pack(side=TOP)
-
showFrame.pack(side=TOP)
-
GuiMenu(root)
-
fguiChose=FileGuiChose(os.curdir,choseFrame,showFrame)
-
mainloop()
-
if __name__ == '__main__':
-
main()
REF:
python Doc
阅读(4025) | 评论(2) | 转发(0) |