Categories
Python

ZIP, Python and TK

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:

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.

Categories
Python

Building GUI with Python and Tk

I have been looking for a decent GUI toolkit to develop some desktop programs. I worked with Java. Didn’t like the idea of typing that much to develop a app. Used php with WinBinder and PHP-GTK. Liked the first one, but the binary I have won’t load the winbinder extension. To use it, I will have to go back to php4. Again I don’t like the idea of using php4 for GUI while using php5 for web development. So again I had to make a swtich. This time I went for wxPython for Python 2.6.0. Alas, though wxPython used to work fine on my XP, it no longer runs on Windows Vista.

Finally, I deceided to work with TK which comes pre-installed with Python. The IDLE, Module Docs and other GUI tools which comes with a standard Python installations are most often developed using TK on Python.

I liked TK quite a bit because the process of developing TK GUI apps are damn easy and great fun. While learning TK, I converted my old console twitter publisher to a TK powered GUI app. Here’s the sourcecode:

Python 3 Source Code:

It’s very comfortable to work on TK. Write less, do more. A good set of widgets and a powerful language like Python as the backend… It’s simply cool 🙂

Categories
Python

Simple Console Clock for Windows with Python

The code is self explanatory:

Python 3 Source Code:

It displays a clock on Windows Command Prompt and updates it every second. It mainly demonstrates the Timer object of threading library.