-1

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()

1 Answers1

0

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)
Anshumaan Mishra
  • 1,349
  • 1
  • 4
  • 19