如何压缩用户给出的文件?

发布于 2025-01-23 18:10:34 字数 1373 浏览 2 评论 0原文

我想创建一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぃ弥猫深巷。 2025-01-30 18:10:34

enter.get()可能是因为.place()函数返回none,因此enter = none 。
尝试分裂:

enter = Entry(win).place(x=250,y=100)

AS

enter = Entry(win)
enter.place(x=250,y=100)

enter.get() is probably not working because the .place() function returns None and hence enter = None.
Try splitting:

enter = Entry(win).place(x=250,y=100)

as

enter = Entry(win)
enter.place(x=250,y=100)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文