I need to create an OpenGL context in Tkinker, for using it with PyOpenGL Python module.
Tkinker doesn't natively support OpenGL context, but I found this page on PyOpenGL docs, explaining how to use a wrapper included in the module for this: http://pyopengl.sourceforge.net/documentation/context/
I tried to run the provided code but I got a message saying TOGL module was not found. I downloaded the module from http://togl.sourceforge.net/, but couldn't get it to work.
PS. I did the test on Mac OS X, with Python 3.2, using virtualenv.
PyOpenGL provides Python bindings for the Tk OpenGL widget (Togl) but not Togl itself, that is why you had to download it. Now, to install Togl is easy but there isn't a tool ready to perform the task. Since the Python bindings will use Tcl to load the Togl module, the widget needs to live in one of the directories present in Tcl's auto_path
, which is where Tcl looks for loading libraries. What you can do is start a Tcl interpreter, tclsh
, and check which are these directories by doing puts $auto_path
. In my case I copied the directory lib/Togl2.0
(inside the Togl's .tar.gz) to /opt/local/lib/tcl8.5
. You can also extend auto_path
to look for other directories, but I'm not covering that here.
Then I tested using Python 2.7 on Mac OSX. Doing import OpenGL.Tk
tries to load Togl, too bad it fails. The reason is that Togl comes precompiled for i386, since I built Python as a universal binary all I did was run it as arch -i386 python2.7
, and now import OpenGL.Tk
works.