【发布时间】:2016-04-11 07:10:20
【问题描述】:
我对 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 中定义的内容?
【问题讨论】:
标签: python class inheritance qtgui