How to create menu item in OSX Menubar using Pyinstaller packaged Kivy Python application?

僤鯓⒐⒋嵵緔 提交于 2020-08-03 03:06:44

问题


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.

Any suggestion? I guess it will be in the range of PyObjc or AppleScript. Not sure though.


回答1:


I guess this is more to Pyinstaller question that it is as Kivy question.

It's neither :)

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.

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.

Then install PyObjC itself:

pip install pyobjc

There are already some examples (first, another) on creating a status bar icon using PyObjC.

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.




回答2:


The Kivy graphical backend provider is OpenGl, By this way Kivy applications can run on any OS(IOS, Android, Linux, Windows, ...) by unique face. you can using kivy ActionBar to show menu or create a custom widget that is difficult. this link also this one can helping you.




回答3:


If using PyQt, I can easily achieve this. But as I am using Kivy, it seems like I have to resort to other ways

I don't see why you can't just use the PyQt method. Create a separate file that runs the icon that is called by your main Kivy app.
Like PyQt I am sure that Kivy has an exit function that you could override and have it kill the icon thread on exiting the application.

Only potential downside (that I can think of off the top of my head) is that it might run slower than implementing in PyObjC.



来源:https://stackoverflow.com/questions/26815360/how-to-create-menu-item-in-osx-menubar-using-pyinstaller-packaged-kivy-python-ap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!