26

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.

FeliceMente
  • 263
  • 1
  • 3
  • 8
  • 3
    What exactly didn't work with the TOGL module? Did you get an error? If so, post the traceback. – Joel Cornett Nov 01 '12 at 04:31
  • yeah, would be nice if you could elaborate. – Don Question Nov 07 '12 at 21:28
  • just guessing, but the module seems quit old. Maybe running python 2.7 fixes your problem? – jorrebor Nov 13 '12 at 13:50
  • Sorry for not posting the code and for answering so late. I was going to try it again, but could no longer find info about using it with Tkinter in PyOpenGL docs (they just say it's supported). The link I originally pasted no longer works. I'm anyway trying to undestand where to put the togl widget, so I can try again, with both Python 2.7 and 3.3. – FeliceMente Nov 28 '12 at 00:00

1 Answers1

10

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.

mmgp
  • 18,901
  • 3
  • 53
  • 80