pyqt5 menu code example
Example 1: menubar pyqt
menubar = self.menuBar()
file = menubar.addMenu("&File")
open = QAction("&Open", self)
open.setShortcut("Ctrl+O")
file.addAction(open)
save = QAction("&Save",self)
save.setShortcut("Ctrl+S")
file.addAction(save)
open.triggered.connect(lambda: self.yourfunction())
Example 2: pyqt5 menu bar
"""
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()
Example 3: pyqt5 toolbar
toolbar = self.addToolBar("File")
edit=QAction(QtGui.QIcon("edit.png"),"Edit",self)
saveEdit=QAction(QtGui.QIcon("save.png"),"Save",self)
toolbar.addAction(edit)
toolbar.addAction(edit)