简体   繁体   English

Python中的Tkinter OpenGL上下文

[英]Tkinter OpenGL context in Python

I need to create an OpenGL context in Tkinker, for using it with PyOpenGL Python module. 我需要在Tkinker中创建一个OpenGL上下文,以便将它与PyOpenGL Python模块一起使用。

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/ Tkinker本身并不支持OpenGL上下文,但我在PyOpenGL文档中找到了这个页面,解释了如何使用模块中包含的包装器: http//pyopengl.sourceforge.net/documentation/context/

I tried to run the provided code but I got a message saying TOGL module was not found. 我试图运行提供的代码,但我收到一条消息说没有找到TOGL模块。 I downloaded the module from http://togl.sourceforge.net/ , but couldn't get it to work. 我从http://togl.sourceforge.net/下载了该模块,但无法使其工作。

PS. PS。 I did the test on Mac OS X, with Python 3.2, using virtualenv. 我使用virtualenv在Mac OS X上使用Python 3.2进行了测试。

PyOpenGL provides Python bindings for the Tk OpenGL widget (Togl) but not Togl itself, that is why you had to download it. PyOpenGL为Tk OpenGL小部件(Togl)提供Python绑定,但不提供Togl本身的Python绑定,这就是你必须下载它的原因。 Now, to install Togl is easy but there isn't a tool ready to perform the task. 现在,安装Togl很简单,但没有准备好执行任务的工具。 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. 由于Python绑定将使用Tcl来加载Togl模块,因此小部件需要存在于Tcl的auto_path中的一个目录中,这是Tcl查找加载库的位置。 What you can do is start a Tcl interpreter, tclsh , and check which are these directories by doing puts $auto_path . 你可以做的是启动一个Tcl解释器, tclsh ,并通过执行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 . 在我的例子中,我将目录lib/Togl2.0 (在Togl的.tar.gz中)复制到/opt/local/lib/tcl8.5 You can also extend auto_path to look for other directories, but I'm not covering that here. 你也可以扩展auto_path来寻找其他目录,但我不是在这里讨论它。

Then I tested using Python 2.7 on Mac OSX. 然后我在Mac OSX上使用Python 2.7进行了测试。 Doing import OpenGL.Tk tries to load Togl, too bad it fails. 执行import OpenGL.Tk尝试加载Togl,太糟糕了它失败了。 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. 原因是Togl预编译为i386,因为我将Python作为通用二进制文件构建,我将其作为arch -i386 python2.7运行,现在import OpenGL.Tk可以工作。

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

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