Friday, December 16, 2011

Hello World Python GUI with Tkinter on CentOS and FreeBSD


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.


On CentOS 6.1
# python --version
Python 2.6.6

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

# yum install python-matplotlib-tk.i68

# find /usr/lib/python2.6/ -name

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

Hello World
# vim ~/tmp/
# -*- coding: iso-8859-1 -*-

from Tkinter import *

root = Tk()

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


# python ~/tmp/


No comments: