为什么我的文本文件不能用Python Gui传输?

2024-04-25 13:41:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试将过去24小时内修改或创建的任何文本文件从一个文件传输到另一个文件。到目前为止,GUI允许用户选择一个源文件和目标文件,当运行时,不会发生错误,但也不会移动任何文件。有什么我看不到的吗

import shutil
import os
import time
from tkinter import *
import tkinter.filedialog as fdialog


class MainClass():

    def __init__(self, master):
        self.parent=master
        self.gui()


    def gui(self):
        self.Source=StringVar()
        self.Destination=StringVar()

        MySource=Entry(myGUI, textvariable=self.Source).grid(row=9, column=2)
        browse1=Button(myGUI, text="Browse",command=lambda:self.Source.set(fdialog.askdirectory())).grid(row=9, column=3)
        MyDestination=Entry(myGUI, textvariable=self.Destination).grid(row=10, column=2)
        browse2=Button(myGUI,text="Browse",command=lambda:self.Destination.set(fdialog.askdirectory())).grid(row=10, column=3)


        buttonCopy=Button(myGUI, text="  Copy  ", command=self.copyy).grid(row=11, column=3)


    SECONDS_IN_DAY = 24 * 60 * 60
    now = time.time()
    before = now - SECONDS_IN_DAY

    def last_mod_time(fname):
        return os.path.getmtime(fname)

    def copyy(self):
        source_file=self.Source.get()
        if (source_file.endswith(".txt") and last_mod_time(src_fname) > before):
            shutil.copy(source_file, self.Destination.get())


if __name__ == '__main__':
    myGUI=Tk()
    app=MainClass(myGUI)
    myGUI.geometry("400x200+100+200")
    myGUI.mainloop()

Tags: 文件textimportselfsourcetimedefcolumn