我对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
中定义的内容?