我想创建一个GUI来压缩用户输入的文件。Enter.get()不起作用。我也试着把它放在引号里。我们可以为get()方法创建一个变量吗?如果有任何其他方法来检索数据,请告诉我。错误:
Traceback (most recent call last):
File "d:MyProgramsPythonPython_project.py", line 28, in <module>
butt = Button(win, text="Compress",command= zipped())
File "d:MyProgramsPythonPython_project.py", line 17, in zipped
zipname.write('enter.get()', compress_type= zipfile.ZIP_DEFLATED)
File "c:userstanmayappdatalocalprogramspythonpython39libzipfile.py", line 1727, in write
zinfo = ZipInfo.from_file(filename, arcname,
File "c:userstanmayappdatalocalprogramspythonpython39libzipfile.py", line 501, in from_file
st = os.stat(filename)
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'enter.get()'
from tkinter import *
import zipfile
import os
from tkinter import *
win = Tk()
win.geometry("500x500")
win.title("File Compressor")
global enter
global butt
global getenter
def zipped():
zipname = zipfile.ZipFile('compressed.zip','w')
zipname.write('enter.get()', compress_type= zipfile.ZIP_DEFLATED)
zipname.close()
filen = Label(win, text="Enter File Name").place(x=200,y=100)
enter = Entry(win)
enter.place(x=250,y=100)
getenter = enter.__getattribute__
butt = Button(win, text="Compress",command= zipped())
win.mainloop()
enter.get()
可能不工作,因为.place()
函数返回None
,因此返回enter = None
。
尝试拆分:
enter = Entry(win).place(x=250,y=100)
enter = Entry(win)
enter.place(x=250,y=100)