Non top-level opengl widget in tkinter

opengl, python, tkinter

Solution

Looks like the PyOpengl wrapper for togl is using a default root window.

You should be able to get a reference to it via the master attribute of your Opengl widget.

from Tkinter import *
from OpenGL.Tk import *

b=Opengl(height=100,width=100)
root = b.master
f = Frame(root, width=100, bg='blue')
f.pack(side='left', fill='y')
b.pack(side='right', expand=1, fill='both')

root.mainloop()

Problem

I have a existing tkinter gui to which I would like to add a openGL widget. However, it appears that the OpenGL widget only works if it is toplevel. This works: ``` from OpenGL.Tk import * from Tkinter import * herp=Opengl(height=100,width=100) herp.pack() herp.mainloop() ``` But this does not: ``` from OpenGL.Tk import * root=Tk() b=Opengl(root,height=100,width=100) b.pack() root.mainloop() ``` Giving me the following error: ``` Traceback (most recent call last): File "\\sith\user_files\2013-Softerns\new_gui_planning\LearningOpenGL\integration_3.py", line 4, in <module> b=Opengl(root,height=100,width=100) File "C:\Python27_32bit\lib\site-packages\OpenGL\Tk\__init__.py", line 267, in __init__ apply(RawOpengl.__init__, (self, master, cnf), kw) File "C:\Python27_32bit\lib\site-packages\OpenGL\Tk\__init__.py", line 216, in __init__ Widget.__init__(self, master, 'togl', cnf, kw) File "C:\Python27_32bit\lib\lib-tk\Tkinter.py", line 2036, in __init__ (widgetName, self._w) + extra + self._options(cnf)) TclError: invalid command name "togl" ``` Do I need to import togl? The only other thing I could find on this is: http://computer-programming-forum.com/56-python/ece79da9298c54de.htm But their solution does not work for me.

Original source