PyQt4: Where can you make menus? <p>I'm using Python 3 and PyQt4</p> <p>I'm trying to make a simple main window with a menubar. It doesn't work if I try to set up the menubar in the MainWindow initialization but does work if I set it up in some external function. That is, the following does NOT work:</p> <pre><code>import sys from PyQt4 import QtGui class MyMainWindow(QtGui.QMainWindow): def __init__(self, parent=None): super().__init__(parent) centralWidget = QtGui.QWidget() menubar = QtGui.QMenuBar() menu = QtGui.QMenu("File") menu.addAction("New") menubar.addMenu(menu) self.setMenuBar(menubar) self.setCentralWidget(centralWidget) if __name__ == "__main__": app = QtGui.QApplication(sys.argv) mainWindow = MyMainWindow() mainWindow.show() sys.exit(app.exec_()) </code></pre> <p>While if I simply move the menu setup down to the main routine:</p> <pre><code>class MyMainWindow(QtGui.QMainWindow): def __init__(self, parent=None): super().__init__(parent) if __name__ == "__main__": app = QtGui.QApplication(sys.argv) mainWindow = MyMainWindow() centralWidget = QtGui.QWidget() menubar = QtGui.QMenuBar() menu = QtGui.QMenu("File") menu.addAction("New") menubar.addMenu(menu) mainWindow.setMenuBar(menubar) mainWindow.setCentralWidget(centralWidget) mainWindow.show() sys.exit(app.exec_()) </code></pre> <p>Then the menu is created (I know I don't have any actions hooked up, this is stripped down to show the oddity). I thought it might have to do with being in <strong>init</strong> but moving it to another class routine, e.g. setup(self), and then calling that after creating the mainWindow doesn't solve the problem. </p> <p>I seem to be continually baffled by what works and what doesn't in PyQt4. If anyone could point me at some good resources I'd also appreciate it (I've read <strong>Rapid GUI Programming</strong> but find I'm still lost).</p> <p>Thanks in advance for your help</p>