2

我在设置以下代码生成的图形时遇到问题。当主窗口关闭时它不会关闭。我在主窗口中使用self.setAttribute(Qt.WA_DeleteonClose)过。smd调用函数时,主窗口对象作为父对象传递。即使我已经明确设置了画布的父级,当主窗口关闭时,生成的图也不会关闭。

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()
4

0 回答 0