我想创建新文件,但首先选择目录。 此代码有效,但目录已设置
new_file = input("File name\n")
new_file = new_file.lower().replace(".", "").replace(" ", "_")
print(new_file)
open_file = open('D:\Python projects\%s.py' % new_file, 'w')
也尝试过这样但没有发生
import tkinter as tk
from tkinter import filedialog
root = tk.Tk()
root.withdraw()
file_path = filedialog.askopenfilename()
new_file = input("Name file\n")
open_file = open(f"{file_path}\%s.py" % new_file, 'w')
askdirectory 应该可以工作。
file_path = filedialog.askdirectory