2013-06-28 81 views
0

我有一個現有的tkinter gui,我想添加一個openGL小部件。但是,看起來,OpenGL小部件只有在頂層時纔可用。tkinter中的非頂級opengl小部件

這工作:

from OpenGL.Tk import * 
from Tkinter import * 
herp=Opengl(height=100,width=100) 
herp.pack() 
herp.mainloop() 

但這並不:

from OpenGL.Tk import * 
root=Tk() 
b=Opengl(root,height=100,width=100) 
b.pack() 
root.mainloop() 

給我下面的錯誤:

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" 

我需要進口togl?

我能找到這個問題的唯一另一件事是:

http://computer-programming-forum.com/56-python/ece79da9298c54de.htm

但他們的解決方案並不爲我工作。

回答

3

看起來像togl的PyOpengl包裝器正在使用默認的根窗口。

您應該能夠通過Opengl小部件的主屬性 獲得對它的引用。

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() 
+0

湮沒,你的解決方案完美無缺!對於那些處於相同情況的人,如果你需要在代碼中稍後使用opengl小部件,你可以'提取'根,然後再重新定義opengl小部件。奇蹟般有效。 – code11