使用Python内置库os进行文件操作,并且使用tkinter制作简单界面
os:
- os.path
- os.walk(DIR)
tkinter:
- 窗口操作
- Label组件
- Entry组件
- Text组件
- Button组件
完整代码:
# -*- coding: utf-8 -*-
import os
import tkinter as tk
from tkinter import filedialog as fd
#遍历文件夹,统计文件夹中指定格式的文件数量,返回值:->字典 {文件名:行数},->整数 总行数,->整数 总文件数
def files(file_dir,ext):
if(ext!=''):
filenames={}
lines=0
all_lines=0
name=''
for root, dirs, files in os.walk(file_dir):
for file in files:
if os.path.splitext(file)[1] == ext:
name=os.path.join(root,file)
try:
with