我正在构建一个使用PYQT选择文件的简单GUI,我正在使用Spyder IDE。当我尝试使用红色“X”按钮关闭GUI并再次运行该文件时,会弹出一条警告消息:
No Python shell is currently selected to run **readFile.py**
Please select or open a new Python interpreter and try again
如何让红色X按钮重新初始化解释器和控制台,而不必每次都手动执行?这是我的代码:
from PyQt4 import QtGui
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
vbox = QtGui.QVBoxLayout()
lbl = QtGui.QLabel('Please Choose Excel File',self)
openButton = QtGui.QPushButton('Choose File')
openButton.clicked.connect(self.showDialog)
vbox.addWidget(lbl)
vbox.addWidget(openButton)
self.setLayout(vbox)
self.setGeometry(300,300,350,300)
self.setWindowTitle('file Dialog')
self.show()
def showDialog(self):
fname = QtGui.QFileDialog.getOpenFileName(self, 'Open file', '/home')
print(fname)
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()