#coding:utf-8
from tkinter import *
import os
def fc():
if input.get() == "":
txt.insert(END,"请输入有效数据"+"\n")
else:
path_list = os.listdir(input.get())#获取gui上输入的值
for picture_name in path_list:
with open("Remove_suffix.txt", "a") as f:
f.write(picture_name.split(".")[0] + "\n")
print("去掉后缀名:", picture_name.split(".")[0])
txt.insert(END, picture_name.split(".")[0]+"\n")
input.delete(0, END)
with open("Suffix_exists.txt", "a") as f:
f.write(picture_name + "\n")
print("存在后缀名:", picture_name.split()[0])
txt.insert(END, picture_name.split()[0]+"\n")
windos = Tk()
windos.geometry("460x240")#设置gui窗口大小
windos.title("获取文件夹下所有文件名")#gui窗口title名
la = Label(windos,text="请输入文件夹名称")#gui页面title名称
la.place(relx=0.1,rely=0.1,relwidth=0.8,relheight=0.1)
input = Entry(windos)#输入框设置
input.place(relx=0.35,rely=0.2,relwidth=0.3,relheight=0.1)
button = Button(windos,text="确定",command=fc)#按钮设置名字,按钮执行方法
button.place(relx=0.55,rely=0.2,relwidth=0.1,relheight=0.1)
txt = Text(windos)#gui输出页面
txt.place(relx=0.25,rely=0.3,relwidth=0.5,relheight=0.5)
windos.mainloop()#启动
#if __name__ == '__main__':
# fc()
遍历文件夹下所有文件名,并存放在txt中,分带后缀名与不带后缀名的(tkinter库)
最新推荐文章于 2022-08-31 14:00:47 发布