我正在努力让波纹管代码(MWE)工作。
预期行为:关闭所有窗口后 python 退出
观察到的行为:python 继续运行
有人知道为什么 python 不退出吗?
#!/usr/bin/env python
import wx
from vispy import scene
class Canvas(scene.SceneCanvas):
def __init__(self, *args, **kwargs):
scene.SceneCanvas.__init__(self, *args, **kwargs,)
class VispyFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, -1, "Vispy Frame", wx.DefaultPosition, size=(500, 500))
self.Bind(wx.EVT_CLOSE, self.on_close)
self.Bind(wx.EVT_SHOW, self.on_show)
self.canvas = Canvas(app="wx", parent=self)
def on_close(self, event):
print("close")
self.canvas.app.quit()
self.canvas.close()
self.Destroy()
def on_show(self, event):
print("show")
self.canvas.show()
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "WX Frame")
self.panel = wx.Panel(self, -1)
button = wx.Button(self.panel, label="VISPY")
self.Bind(wx.EVT_BUTTON, self.newwindow, button)
def newwindow(self, event):
secondWindow = VispyFrame(parent=self.panel)
secondWindow.Show()
app = wx.App(False)
frame = MainFrame()
frame.Show(True)
app.MainLoop()