简体   繁体   English

tkinter 中的非顶级 opengl 小部件

[英]Non top-level opengl widget in tkinter

I have a existing tkinter gui to which I would like to add a openGL widget.我有一个现有的 tkinter gui,我想向其中添加一个 openGL 小部件。 However, it appears that the OpenGL widget only works if it is toplevel.但是,似乎 OpenGL 小部件只有在顶级时才有效。

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?我需要导入 togl 吗?

The only other thing I could find on this is:我唯一能找到的另一件事是:

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

But their solution does not work for me.但是他们的解决方案对我不起作用。

Looks like the PyOpengl wrapper for togl is using a default root window. 看起来togl的PyOpengl包装器正在使用默认的根窗口。

You should be able to get a reference to it via the master attribute of your Opengl widget. 您应该能够通过您的Opengl小部件的master属性获得对此的引用。

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

on linux i install it using those commands, then the example above are worked for me:在 linux 上,我使用这些命令安装它,然后上面的示例对我有用:

sudo apt update
sudo apt install togl-demos

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM