我正在使用 PyQt,为了将我的应用程序打包到 Mac,我正在使用 py2app。
如何将“关于框”添加到主菜单:
看起来像这个例子:
最佳答案
要在那里添加“关于”菜单,您只需将其添加到 menuBar()
的 Help
子菜单中即可。
import sys
from PySide import QtGui, QtCore
class Window(QtGui.QMainWindow):
def __init__(self):
super(Window, self).__init__()
help_menu = QtGui.QMenu('&Help')
about = help_menu.addAction('&About')
about.triggered.connect(self.show_about)
self.menuBar().addMenu(help_menu)
def show_about(self):
print 'shown'
app = QtGui.QApplication(sys.argv)
win = Window()
win.show()
app.exec_()
问题是应用程序的标题将是python
,而About
将是About python
。要改变这一点,由于您已经使用 py2app,您应该查看 this question
对于 PyQt4 来说有点不同。请参阅documentation .
两个相关的事情:
-
Do not call QMainWindow.menuBar() to create the shared menu bar, because that menu bar will have the QMainWindow as its parent. You must create a menu bar that does not have a parent.
menuBar = QtGui.QMenuBar(None)
-
The application name is fetched from the Info.plist file (see note below). If this entry is not found no About item will appear in the Application Menu.
关于python - 如何使用 pyqt 和 py2app 将 "About box"添加到 Mac 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18877597/