menubar in pyqt5 code example

Example 1: menubar pyqt

menubar = self.menuBar() # create our menubar
file = menubar.addMenu("&File") # create a file menu
open = QAction("&Open", self) # create a QAction
open.setShortcut("Ctrl+O") # set a shortcut for it
file.addAction(open) # and add it to our menu

# create another one and add it again to our menu
save = QAction("&Save",self) 
save.setShortcut("Ctrl+S")
file.addAction(save)

# and if you want to connect your QActions to your slots you can do it like:
open.triggered.connect(lambda: self.yourfunction())

Example 2: pyqt5 menu bar

#!/usr/bin/python

"""
ZetCode PyQt5 tutorial

This program creates a statusbar.

Author: Jan Bodnar
Website: zetcode.com
"""

import sys
from PyQt5.QtWidgets import QMainWindow, QApplication


class Example(QMainWindow):

    def __init__(self):
        super().__init__()

        self.initUI()

    def initUI(self):
        self.statusBar().showMessage('Ready')

        self.setGeometry(300, 300, 250, 150)
        self.setWindowTitle('Statusbar')
        self.show()


def main():
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()