如何压缩用户给出的文件?
我想创建一个GUI,该GUI压缩用户输入的文件。 enter.get()不起作用。我也尝试将其放入倒逗号中。我们可以为get()方法做一个变量吗?如果还有其他检索数据的方法,请启发我。 错误:
Traceback (most recent call last):
File "d:\MyPrograms\Python\Python_project.py", line 28, in <module>
butt = Button(win, text="Compress",command= zipped())
File "d:\MyPrograms\Python\Python_project.py", line 17, in zipped
zipname.write('enter.get()', compress_type= zipfile.ZIP_DEFLATED)
File "c:\users\tanmay\appdata\local\programs\python\python39\lib\zipfile.py", line 1727, in write
zinfo = ZipInfo.from_file(filename, arcname,
File "c:\users\tanmay\appdata\local\programs\python\python39\lib\zipfile.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()
I wanted to create a GUI which compress the file entered by user.
enter.get() isn't working. I tried putting it in inverted commas as well. Can we make a variable for get() method? If there is any other method to retrieve the data please enlighten me.
Error:
Traceback (most recent call last):
File "d:\MyPrograms\Python\Python_project.py", line 28, in <module>
butt = Button(win, text="Compress",command= zipped())
File "d:\MyPrograms\Python\Python_project.py", line 17, in zipped
zipname.write('enter.get()', compress_type= zipfile.ZIP_DEFLATED)
File "c:\users\tanmay\appdata\local\programs\python\python39\lib\zipfile.py", line 1727, in write
zinfo = ZipInfo.from_file(filename, arcname,
File "c:\users\tanmay\appdata\local\programs\python\python39\lib\zipfile.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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
enter.get()
可能是因为.place()
函数返回none
,因此enter = none 。
尝试分裂:
AS
enter.get()
is probably not working because the.place()
function returnsNone
and henceenter = None
.Try splitting:
as