pyqt5 open window menubar

Solutions on MaxInterview for pyqt5 open window menubar by the best coders in the world

showing results for - "pyqt5 open window menubar"
Ari
16 Jun 2020
1# Taken from https://www.learnpyqt.com/tutorials/creating-multiple-windows/
2# and edited some few things
3
4import sys
5from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QMenuBar, QAction
6
7
8# New window to be created
9class AnotherWindow(QWidget):
10	def __init__(self):
11    	super(AnotherWindow, self).__init__()
12        """
13        Works the same as a normal window (it's a window) so you
14        can add things like `setWindowTitle` and such.
15        """
16        
17        
18# Main window
19class MainWindow(QMainWindow):
20	def __init__(self):
21    	super(MainWindow, self).__init__()
22        # Create action to be placed in the menu bar
23        action = QAction('&New window'. self)
24        action.triggered.connect(self.new_window)
25        # Create menu bar
26        menubar = QMenuBar(self)
27        self.setMenuBar(menubar)
28        # Add action to menu bar
29        menubar.addAction(action)
30        
31    # Method for calling the other window
32 	def new_window(self):
33    	# Important! Add `self` to keep the window open until closed
34    	self.another_window = AnotherWindow()
35        self.another_window.show()
36        
37
38app = QApplication(sys.argv)
39window = MainWindow()
40window.show()
41sys.exit(app.exec_())