Python GUI 实现功能

2021-12-12  本文已影响0人  jinhm007
import tkinter as tk
import os

window = tk.Tk()
window.title("Check wendor files")
window.geometry('450x300')
# user information
tk.Label(window, text='Path: ').place(x=50, y=50)
var_path = tk.StringVar()
entry_path = tk.Entry(window, textvariable=var_path, width=40, show=None)
# var_path.set('please input  the path to check file')
print(entry_path.get())
entry_path.place(x=100, y=50)
path = r"D:\test"


# 遍历文件夹

def walkFile():
    usr_path = var_path.get()
    for root, dirs, files in os.walk(usr_path):

        # root 表示当前正在访问的文件夹路径
        # dirs 表示该文件夹下的子目录名list
        # files 表示该文件夹下的文件list
        # 遍历文件
        for f in files:
            var = os.path.join(root, f)
            print(var)
            t.insert("insert", var+"\n")

# walkFile(path)
btn_login = tk.Button(window, text='Start', width=10, command=walkFile)
btn_login.place(x=150, y=100)
t = tk.Text(window, height=13,width=50)
t.place(x=10, y=140)
window.mainloop()

上一篇下一篇

猜你喜欢

热点阅读