我正在写一个与我也在写的C++库接口(interface)的python tkinter应用程序。 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的源代码。

最佳答案

您不能将GLUT与其他窗口框架混合使用。至少并非没有很多痛苦。但是人们不得不怀疑:GLUT中必须使用什么?通过一些额外的模块,您可以在TkInter Tkinter OpenGL context in Python中创建一个OpenGL上下文。

关于python - 我可以允许tkinter的mainloop()和GLUT的glutMainLoop()同时运行吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/63125202/

10-12 01:17