The title says it all. Here’s a very simple program written in Python and TK which can extract a ZIP file to the selected location.
Python 3 – Source Codes:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
import zipfile import tkinter, tkinter.filedialog root = tkinter.Tk() root.title("ZIP Unzipper") frame = tkinter.Frame(root) btn = tkinter.Button(frame) inputBox = tkinter.Entry(frame) label = tkinter.Label(frame,text="Target Location:") def work(): zipF = zipfile.ZipFile(tkinter.filedialog.askopenfile().name) zipF.extractall(inputBox.get()) btn['text'] = "Choose & Extract" btn['command'] = work label.pack() inputBox.pack() btn.pack() frame.pack() root.maxsize(100,100) root.minsize(100,100) root.mainloop() |
Explanations It creates a TK interface with a button and a text entry widgets. Clicking on the button invokes the work() function. The work() function displays a filedialog and prompts you to choose a ZIP file. Then it creates a new ZipFile object using the file location. The extractall() method of the ZipFile object extracts all contents of the archive into the directory specified using the inputBox text entry widget. We call inputBox.get() to get it’s value. If the value of target location is null, the files are extracted into the current working directory. In case of an invalid target location, it prints out error messages to the console.
It’s a very basic program with a little functionality. It mainly demonstrates the use of TK and Python to write GUI programs that really does something.
One reply on “ZIP, Python and TK”
Hi,
I hope u can help me with an application which i can extract file in mobile phone like “winrar, winzip” so that i can run mig33 multi kick on my nokia n79.