【发布时间】:2020-11-17 08:48:58
【问题描述】:
我正在编写一个 python tkinter 应用程序,它与我也在编写的 C++ 库接口。 C++ 库包含一个封装了一些 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 窗口启动,我的 tkinter GUI 就会失去功能。
我确实尝试将std::thread 对象添加到我的包装类中,但glutMainLoop 在退出后似乎退出了整个进程,这意味着在线程中运行它不利于干净退出。
我在想我可以使用 GLUT 的 atexit 向 tkinter 发出信号,它需要关闭并加入线程,但理想情况下,当我关闭 GLUT 窗口时,该过程不会结束(我不认为这会给一个干净的出口)。
是否有可能让这两个循环同时运行并且干净利落?
我想避免修改 GLUT 的源代码。
【问题讨论】:
标签: python c++ opengl tkinter glut