我可以同时允许 tkinter 的 mainloop() 和 GLUT 的 glutMainLoop() 运行 吗?
Can I allow tkinter's mainloop() and GLUT's glutMainLoop() run concurrently?
我正在编写一个 python tkinter 应用程序,它与我也在编写的 C++ 库进行交互。 C++ 库包含一个 class,它包装了一些 GLUT 的函数。
我的主要功能 (python) 看起来像这样:
import sys
import tkinter as tk
import myCustomCppLibrary
#This sets up the GLUT bindings.
myCustomCppLibrary.Initialize()
root = tk.Tk()
# ... some stuff
#Something in mainloop() eventually calls glutMainLoop()
root.mainloop()
myCustomCppLibrary.Finalize()
sys.exit(0)
不幸的是,glutMainLoop
阻止了 root.mainloop()
,这意味着一旦我的 GLUT window 启动,我的 tkinter GUI 就无法正常工作。
我确实尝试将 std::thread
对象添加到我的包装器 class 但 glutMainLoop
似乎在退出后退出整个过程,这意味着 运行线程不利于干净退出。
我在想我可以使用 GLUT 的 atexit
向 tkinter 发出它需要关闭并加入线程的信号,但理想情况下当我关闭 GLUT window 时进程不会结束(我也不认为这会提供一个干净的出口。
是否可以同时进行这两个循环运行,并且干净利落?
我想避免修改 GLUT 的源代码。
您不能将 GLUT 与其他窗口框架混合使用。至少不是没有经历很多痛苦。但人们不得不怀疑:GLUT 中有什么是您 必须 使用的?使用一些额外的模块,您可以在 TkInter Tkinter OpenGL context in Python
中创建一个 OpenGL 上下文
我正在编写一个 python tkinter 应用程序,它与我也在编写的 C++ 库进行交互。 C++ 库包含一个 class,它包装了一些 GLUT 的函数。
我的主要功能 (python) 看起来像这样:
import sys
import tkinter as tk
import myCustomCppLibrary
#This sets up the GLUT bindings.
myCustomCppLibrary.Initialize()
root = tk.Tk()
# ... some stuff
#Something in mainloop() eventually calls glutMainLoop()
root.mainloop()
myCustomCppLibrary.Finalize()
sys.exit(0)
不幸的是,glutMainLoop
阻止了 root.mainloop()
,这意味着一旦我的 GLUT window 启动,我的 tkinter GUI 就无法正常工作。
我确实尝试将 std::thread
对象添加到我的包装器 class 但 glutMainLoop
似乎在退出后退出整个过程,这意味着 运行线程不利于干净退出。
我在想我可以使用 GLUT 的 atexit
向 tkinter 发出它需要关闭并加入线程的信号,但理想情况下当我关闭 GLUT window 时进程不会结束(我也不认为这会提供一个干净的出口。
是否可以同时进行这两个循环运行,并且干净利落?
我想避免修改 GLUT 的源代码。
您不能将 GLUT 与其他窗口框架混合使用。至少不是没有经历很多痛苦。但人们不得不怀疑:GLUT 中有什么是您 必须 使用的?使用一些额外的模块,您可以在 TkInter Tkinter OpenGL context in Python
中创建一个 OpenGL 上下文