我刚开始学习Python,却完全没有编程经验。下面的代码对我来说毫无意义,因为我不断收到(无此类文件)错误。
import tkinter
from tkinter import filedialog
from zipfile import ZipFile
mainwin = tkinter.Tk()
mainwin.sourceFile = ''
def chooseFile():
mainwin.sourceFile = filedialog.askopenfilename(parent=mainwin, initialdir= '/', title='Please select a directory')
browsebutton = tkinter.Button(mainwin, text = "Choose File", width = 20, height = 3, command = chooseFile)
browsebutton.place(x = 50,y = 50)
browsebutton.width = 100
zip = ZipFile(mainwin.sourceFile)
mainwin.mainloop()
print(mainwin.sourceFile)
因此,即使创建按钮后,sourceFile也没有任何值,但是如果删除
zip = ZipFile(mainwin.sourceFile)
即使我销毁了窗户,它也会有价值吗?