問題描述
為了在我的 Pyinstaller 打包的 Kivy Python 應用程序中實現原生感,我想在 OSX 菜單欄中創建菜單項.如果使用 PyQt,我可以輕松實現這一點.但是由于我使用的是 Kivy,我似乎不得不求助于其他方式.
To achieve sense of nativeness in my Pyinstaller packaged Kivy Python application, I would like to create menu item in OSX menu bar. If using PyQt, I can easily achieve this. But as I am using Kivy, it seems like I have to resort to other ways.
有什么建議嗎?我猜它會在 PyObjc 或 AppleScript 的范圍內.不過不確定.
Any suggestion? I guess it will be in the range of PyObjc or AppleScript. Not sure though.
推薦答案
我想這更像是 Pyinstaller 的問題,它是 Kivy 的問題.
I guess this is more to Pyinstaller question that it is as Kivy question.
兩者都不是:)
PyInstaller 只是將 python 應用程序包裝到一個看起來像本機的 OS X 應用程序包中.
由于 Kivy 無法在 OS X 中創建菜單欄圖標,因此您必須堅持使用 PyObjC.
PyInstaller just wraps the python application into a native-looking OS X application bundle.
Since Kivy doesn't have the ability to create a menu bar icon in OS X, you have to stick with PyObjC.
首先,您必須安裝 Xcode(如果尚未安裝).您可以從 App Store 或 Apple 的開發者中心 下載它.
First, you've got to install Xcode (if not installed yet). You can download it from the App Store or from the Apple's Developer Center.
然后安裝 PyObjC 本身:
Then install PyObjC itself:
pip install pyobjc
已經有一些例子了(first, another) 關于使用 PyObjC 創建狀態欄圖標.
There are already some examples (first, another) on creating a status bar icon using PyObjC.
還有一個很棒的庫,叫做 rumps
,它極大地簡化了代碼需要制作狀態欄圖標、菜單和操作.也許它可以幫助您進行狀態欄交互.
There's also an awesome library called rumps
which greatly simplifies the code needed to make status bar icons, menus and actions. Perhaps it may help you with status bar interacting.
這篇關于如何使用 Pyinstaller 打包的 Kivy Python 應用程序在 OSX 菜單欄中創建菜單項?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!