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:
———————————————-
import tkinter
root = tkinter.Tk();
root.title(“maSnun”)
mainFrame = tkinter.Frame(root)
topFrame = tkinter.Frame(mainFrame)
resFrame = tkinter.Frame(mainFrame)
topFrame["height"] = 50
topFrame["width"] = 400
inputBox = tkinter.Entry(topFrame)
okButton = tkinter.Button(topFrame)
okButton["text"] = “OK”
okButton["fg"] = “white”
okButton["bg"] = “black”
label = tkinter.Label(resFrame)
label.pack({“side”:”top”})
label["text"] = “”
def ok_act():
global label,inputBox
import sys;
from urllib.request import urlopen,Request;
import base64;
username = “username”;
password = “password”;
url = “http://www.twitter.com/statuses/update.xml”;
status = inputBox.get();
data =”status=”+status;
req = Request(url);
req.data = data;
req.headers['Authorization'] = ‘Basic %s’ % (base64.b64encode((username + “:” + password).encode())).decode();
# req.headers['User-Agent'] = ‘Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.20) Gecko/20081217 Firefox/2.0.0.20′;
urlopen(req);
label["text"] = “Tweet Published!!”
label.pack({“side”:”top”})
okButton["command"] = ok_act
inputBox.pack({“side”:”left”})
okButton.pack()
topFrame.pack({“side”:”top”})
topFrame.pack({“side”:”top”});
resFrame.pack({“side”:”top”})
mainFrame.pack()
root.maxsize(400,400)
root.minsize(400,400)
root.mainloop();
———————————————-
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