pyqt5 tkinter
目的:要求在目录下创建文件夹,并命名
将path路径改为你所要测试的文件路径
from tkinter import *
from tkinter.filedialog import askdirectory
tiw = Tk()
tiw.title("请输入文件夹名称:")
tiw.geometry('300x50')
en = Entry(tiw, show=None)
Label(tiw, text="请输入文件夹名称:")
en.pack()
path ="C:/Users/Gretel/PycharmProjects/S-VCD"
def app():
et = en.get()
tiw.destroy()
mkpath = path + "/" + et
def return_path(path):
import os
path = path.strip()
Exist = os.path.exists(path)
if not Exist:
os.makedirs(path)
print(path + ' 创建成功')
return True
else:
print(path + ' 目录已存在')
return False
return_path(mkpath)
btn = Button(tiw, text="OK", width=10, height=2, command=app)
btn.pack()
tiw.mainloop()
测试结果:
有什么不对的地方请批评指正!sx