Python 中的 Tkinter OpenGL 上下文 [英] Tkinter OpenGL context in Python

查看:114
本文介绍了Python 中的 Tkinter OpenGL 上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在 Tkinker 中创建一个 OpenGL 上下文,以便与 PyOpenGL Python 模块一起使用.

I need to create an OpenGL context in Tkinker, for using it with PyOpenGL Python module.

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

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/

我尝试运行提供的代码,但收到一条消息,提示未找到 TOGL 模块.我从 http://togl.sourceforge.net/ 下载了该模块,但无法让它工作.

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.

附注.我在 Mac OS X 上使用 Python 3.2 和 virtualenv 进行了测试.

PS. I did the test on Mac OS X, with Python 3.2, using virtualenv.

推荐答案

PyOpenGL 为 Tk OpenGL 小部件 (Togl) 提供 Python 绑定,但不提供 Togl 本身,这就是您必须下载它的原因.现在,安装 Togl 很容易,但没有准备好执行任务的工具.由于 Python 绑定将使用 Tcl 加载 Togl 模块,因此小部件需要位于 Tcl 的 auto_path 中的目录之一中,这是 Tcl 查找加载库的地方.您可以做的是启动一个 Tcl 解释器,tclsh,并通过执行 puts $auto_path 来检查这些目录.就我而言,我将目录 lib/Togl2.0(在 Togl 的 .tar.gz 中)复制到 /opt/local/lib/tcl8.5.您还可以扩展 auto_path 以查找其他目录,但我不在这里介绍.

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.

然后我在 Mac OSX 上使用 Python 2.7 进行了测试.执行 import OpenGL.Tk 尝试加载 Togl,可惜失败了.原因是 Togl 是为 i386 预编译的,因为我将 Python 构建为通用二进制文件,所以我所做的只是将它作为 arch -i386 python2.7 运行,现在 import OpenGL.Tk有效.

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.

这篇关于Python 中的 Tkinter OpenGL 上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆