Friday, December 16, 2011

Hello World Python GUI with Tkinter on CentOS and FreeBSD

Background


Tkinter is a Python binding to the Tk GUI toolkit. It is the standard Python interface to the Tk GUI toolkit[1] and is Python's de-facto standard GUI,[2] and is included with the standard Windows install of Python.

As with most other modern Tk bindings, Tkinter is implemented as a Python wrapper around a complete Tcl interpreter embedded in the Python interpreter. Tkinter calls are translated into Tcl commands which are fed to this embedded interpreter, thus making it possible to mix Python and Tcl in a single application.
Python 2.7 and Python 3.1 incorporate the "themed Tk" ("ttk") functionality of Tk 8.5.[3][4] This allows Tk widgets to be easily themed to look like the native desktop environment in which the application is running, thereby addressing a long-standing criticism of Tk (and hence of Tkinter).
There are several popular GUI library alternatives available, such as wxPython, PyQt and PyGTK.

From:
http://en.wikipedia.org/wiki/Tkinter

On CentOS 6.1
# python --version
Python 2.6.6

# yum list | grep lib-tk
python-matplotlib-tk.i686 0.99.1.2-1.el6 @base

# yum install python-matplotlib-tk.i68

# find /usr/lib/python2.6/ -name Tkinter.py
/usr/lib/python2.6/lib-tk/Tkinter.py

On FreeBSD 8.2
# cd /usr/ports/x11-toolkits/py-tkinter/ ; make install clean

# python --version
Python 2.7.2

# find /usr/local/lib/python2.7/ -name Tkinter.py
/usr/local/lib/python2.7/lib-tk/Tkinter.py

Hello World
# vim ~/tmp/hello_world.py
#!/usr/bin/python
# -*- coding: iso-8859-1 -*-

from Tkinter import *

root = Tk()

w = Label(root, text="Hello, world!")
w.pack()

root.mainloop()

# python ~/tmp/hello_world.py

Reference:
http://sebsauvage.net/python/gui/
http://www.tkdocs.com/tutorial/index.html

No comments: