【发布时间】:2018-08-16 08:30:45
【问题描述】:
我在使用 PyQt5 构建带有菜单栏的 GUI 窗口时出现了问题。
这是我的代码:
import sys
from PyQt5.QtWidgets import QMainWindow, QAction, QApplication
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
bar = self.menuBar()
example1 = QAction('Exit', self)
example1.setShortcut('Ctrl+E')
example1.triggered.connect(self.close)
example2 = QAction('xit', self)
example2.setShortcut('Ctrl+A')
example2.triggered.connect(self.close)
example3 = QAction('Quit', self)
example3.setShortcut('Ctrl+Q')
example3.triggered.connect(self.close)
fileMenu = bar.addMenu('File')
fileMenu.addAction('NNN')
fileMenu.addAction(example1)
fileMenu.addAction(example2)
fileMenu.addAction(example3)
self.setGeometry(300, 300, 300, 200)
self.setWindowTitle('Menu Example')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
当我运行它时,菜单栏如下所示:
如图所示,“退出”和“退出”消失了,但快捷方式有效。
我的环境:Python 3.6.5,PyQt 5.11.1,MAC_OS 10.13.5
【问题讨论】:
-
它显示在 Windows 上,但我不了解 Mac
-
在 Ubuntu 16.04、Python 3.5.2 和 PyQt 5.10.0 中运行良好
-
在 Ubuntu 18.04 中也可以使用 Python 3.6.5 和 PyQt 5.10.1。
-
基于 cmets,这似乎是 Mac 特有的问题。您可能需要准备好在他们的问题跟踪器中提交错误报告。
-
在 Ubuntu 16.04 上很好:framapic.org/kbUxJUA6bo1m/iOlbFwAp99hf.png
标签: python macos pyqt pyqt5 menubar