Save App with self MenuBar
-
Hi,
I've create self menuBar with the button : File, Save, Save As, etc..And i would like to save my Python File with the Windows Explorer, but i completely stuck for the rest of the code.
self.saveAsAction.setText(_translate("MainWindow", "Save To...")) self.saveAsAction.setShortcut(_translate("MainWindow", "Ctrl+Shift+S")) self.saveAsAction.triggered.connect(self.saveAs) def saveAs(self):If you have any idea that could unblock me, i'll take it !
Thanks
-
You probably want to just use https://doc.qt.io/qt-5/qfiledialog.html#getSaveFileName
-
Hi, and thanks for your answer.
I continue with the documentation of Qt, but i'm stuck again :saveAction = QtGui.QAction("&Save File", self) self.saveAction.setText(_translate("MainWindow", "Save To")) self.saveAction.setShortcut(_translate("MainWindow", "Ctrl+S")) self.saveAction.setStatusTip('Save File') self.saveAction.triggered.connect(self.file_save) self.mainMenu = self.menubar() self.fileMenu.addAction(saveAction) def file_save(self): name = QtGui.QFileDialog.getSaveFileName(self, 'Save File') file = open(name, 'w') text = self.textEdit.toPlainText() file.write(text) file.close()I've an error in this line :
saveAction = QtGui.QAction("&Save File", self)AttributeError: module 'PyQt5.QtGui' has no attribute 'QAction'
I don't know how to solve it
-
Hi,
Because QAction is part of the widgets module.
You have that information in the small table at the top of the documentation.
-
@SGaist Hi, if i understand, this line :
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit, QFileDialog, QTextEdit, QActionis enough ?
-
@SGaist Hi, if i understand, this line :
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit, QFileDialog, QTextEdit, QActionis enough ?
@Zayle said in Save App with self MenuBar:
@SGaist Hi, if i understand, this line :
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit, QFileDialog, QTextEdit, QActionis enough ?
If your remove the QtGui. where you use QAction.