我在设置由以下代码生成的数字时遇到问题。当主窗口关闭时它不会关闭。我在主窗口中使用了self.setAttribute(Qt.WA_DeleteonClose)。主窗口对象在调用smd函数时作为父对象传递。尽管我已经明确设置了canvas的父级,但是当关闭mainwindow时,生成的图形不会关闭。有什么原因?谢谢。
def smd(self,parent):
from pylab import *
import matplotlib
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
from matplotlib.figure import Figure
import pylab as p
sm = [1,2,3]
fig = p.figure()
ax = fig.add_subplot(111)
ax.bar(range(len(sm)),sm,align='center')
ax.set_xticks(range(len(sm)))
canvas = FigureCanvas(fig)
canvas.setParent(parent)
#p.setParent(self)
canvas.draw()
fig.setParent(parent)
print "parent is ", parent, canvas.parent()
p.show()