QMenubar | MenuBar in Qt



from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(820, 640)

self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(180, 190, 291, 201))

font = QtGui.QFont()
font.setPointSize(26)
self.label.setFont(font)
self.label.setObjectName("label")
MainWindow.setCentralWidget(self.centralwidget)

self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 30))
self.menubar.setObjectName("menubar")
self.menuFile = QtWidgets.QMenu(self.menubar)
self.menuFile.setObjectName("menuFile")
self.menuEdit = QtWidgets.QMenu(self.menubar)
self.menuEdit.setObjectName("menuEdit")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)

self.actionNew = QtWidgets.QAction(MainWindow)
self.actionNew.setObjectName("actionNew")
self.actionSave = QtWidgets.QAction(MainWindow)
self.actionSave.setObjectName("actionSave")
self.actionCopy = QtWidgets.QAction(MainWindow)
self.actionCopy.setObjectName("actionCopy")
self.actionCut = QtWidgets.QAction(MainWindow)
self.actionCut.setObjectName("actionCut")
self.actionPaste = QtWidgets.QAction(MainWindow)
self.actionPaste.setObjectName("actionPaste")

self.menuFile.addAction(self.actionNew)
self.menuEdit.addAction(self.actionSave)
self.menuEdit.addAction(self.actionCopy)
self.menuEdit.addAction(self.actionCut)
self.menuEdit.addAction(self.actionPaste)
self.menubar.addAction(self.menuFile.menuAction())
self.menubar.addAction(self.menuEdit.menuAction())

self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)

self.actionNew.triggered.connect(lambda:self.clicked("New File
                                                            created"))
self.actionSave.triggered.connect(lambda: self.clicked("File
                                                            saved"))
self.actionCopy.triggered.connect(lambda: self.clicked("File
                                                            Copied"))
self.actionPaste.triggered.connect(lambda: self.clicked("File
                                                            Pasted"))
self.actionCut.triggered.connect(lambda: self.clicked("Cut
                                                            Option"))

def clicked(self, text):
self.label.setText(text)
self.label.adjustSize()

def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow",
                                                "MainWindow"))
self.label.setText(_translate("MainWindow", "Wellcome!"))
self.menuFile.setTitle(_translate("MainWindow", "File"))
self.menuEdit.setTitle(_translate("MainWindow", "Edit"))

self.actionNew.setText(_translate("MainWindow", "New"))
self.actionNew.setStatusTip(_translate("MainWindow",
                                                "New File created"))
self.actionNew.setShortcut(_translate("MainWindow", "Ctrl+N"))
self.actionCopy.setText(_translate("MainWindow", "Copy"))
self.actionCopy.setStatusTip(_translate("MainWindow",
                                                       "File Copied"))
self.actionCopy.setShortcut(_translate("MainWindow", "Ctrl+C"))

self.actionCut.setText(_translate("MainWindow", "Cut"))
self.actionCut.setStatusTip(_translate("MainWindow",
                                                        "Cut Option"))
self.actionCut.setShortcut(_translate("MainWindow","Ctrl+X"))

self.actionSave.setText(_translate("MainWindow", "Save"))
self.actionSave.setStatusTip(_translate("MainWindow",
                                                        "File Saved"))
self.actionSave.setShortcut(_translate("MainWindow","Ctrl+S"))

self.actionPaste.setText(_translate("MainWindow", "Paste"))
self.actionPaste.setStatusTip(_translate("MainWindow",
                                                       "File Pasted"))
self.actionPaste.setShortcut(_translate("MainWindow",
                                                            "Ctrl+V"))



if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())



Comments