如何打开文件并将文件保存到新目录?
这是我的代码
from tkinter import *
from tkinter import filedialog
root = Tk()
def browsefunc():
filename = filedialog.askopenfilename(filetypes=(("Pilih PDF", "*.pdf"), ("Semua File", ".*")))
pathlabel.config(text=filename)
browsebutton = Button(root, text="Pilih PDF", command=browsefunc)
browsebutton.pack()
pathlabel = Label(root)
def savefunc():
filename = filedialog.asksaveasfile(initaldir="/", filetypes=(("PDF","*.pdf"),("Semua File", ".*")))
pathlabel.config(text=filename)
savebutton = Button(root, text="PDF", command=savefunc)
savebutton.pack()
pathlabel = Label(root)
pathlabel.pack()
mainloop()
我无法保存文件
答案 0 :(得分:1)
import shutil
shutil.copy('dir1/file.txt', 'dir2/file_copy.txt')