Python QtGui:类之间变量的继承

时间:2016-04-11 07:10:21

标签: python class inheritance qtgui

我对GUI很新,我对变量的继承有一个快速的问题。

在我的GUI中,我有两个按钮,一个选择xlsx文件,另一个选择图形。下面的第一个class设置按钮并选择文件:

class Example(QtGui.QWidget):

def __init__(self):
    super(Example, self).__init__()

    self.initUI()

def initUI(self):

    vBoxLayout = QtGui.QVBoxLayout(self)

    file_btn = QtGui.QPushButton('Select File', self)
    file_btn.clicked.connect(self.get_graph_file)

    graphing_btn = QtGui.QPushButton('Plot Graph', self)
    graphing_btn.clicked.connect(Plotting_Graph)

    self.show()

def get_graph_file(self):

    fname_graphfile = QtGui.QFileDialog.getOpenFileName(self, 'Open file', '/Users/.../', 'excel files (*.xlsx)')

...第二个应继承fname_graphfile并绘制图形(我只添加了一些图形代码)......

class Plotting_Graph(Example):

def __init__(self):

    self.PlottingGraph()

def PlottingGraph(self):

    xl = ef(fname_graphfile[0])......

运行时,会出现错误global name 'fname_graphfile' is not defined

如何让第二个class记住我之前class中定义的内容?

0 个答案:

没有答案