Python GUI: 使用对话框选择文件和输出路径并处理文件内容
import tkinter as tk from tkinter import filedialog
root = tk.Tk() root.withdraw()
选择文件对话框
file_path = filedialog.askopenfilename()
选择输出路径对话框
output_path = filedialog.askdirectory()
打开文件并读取内容
with open(file_path, 'r') as f: content = f.read()
处理文件内容
processed_content = content.upper()
写入处理后的内容到新文件
with open(output_path + '/processed_file.txt', 'w') as f: f.write(processed_content)
原文地址: https://www.cveoy.top/t/topic/m06Q 著作权归作者所有。请勿转载和采集!