Search code examples
pythonkivy

How to make Kivy app stay in the Task Bar on close


How to make the Kivy app stay in the Task Bar on close and how to add a list to manage it as I showed in the following pictures, Can anyone please show me where is that documented or I can read about it?

here is an example:

enter image description here

enter image description here


Solution

  • I had a similar problem some time ago making a tray music app and how i did it was like this:

    • Install pystray with pip: pip install pystray
    • Import both pystray and threading

    As soon as the app starts, i.e inside the on_start function of your app class, use pystray to make a tray icon:

    def on_start(self):
        image = Image.open("icon.ico")
        icon = pystray.Icon(name="IconName", icon=image, title="YourApp", menu= (
            pystray.MenuItem('Show', default=True, action=lambda: self.show_app()),
            pystray.MenuItem("Quit", action=lambda: self.close_app(icon)),
        ))
        threading.Thread(target=self.run_icon, args=(icon,)).start()
    
    def run_icon(self, icon):
        icon.run()
    
    @mainthread
    def close_app(self, icon):
        self.root_window.close()
        icon.stop()
    
    @mainthread
    def show_app(self):
        self.root_window.show()
    

    You should also make a custom title bar that has a close button, Which hides the window instead of closing the app like your default title bar, like an icon button that calls this function:

    def end(self):
        self.root_window.hide()