CezarGab / Overlyrics

🎵🟢📃 | Python application that displays real-time song lyrics overlaid on top of other windows in the system.
https://cezargab.github.io/Overlyrics/
MIT License
25 stars 2 forks source link

The program doen't close without using Task Manager #11

Open CezarGab opened 1 month ago

CezarGab commented 1 month ago
          NOTE: The program doen't close. You have to go to the task manager to end task since an error apperars with a label error which when you click ok doen't actually terminate the program. So a `os._exit(1)` function on exit must be implemented.

Originally posted by @xtho25 in https://github.com/CezarGab/Overlyrics/issues/7#issuecomment-2127589697

I'll think about the best solution to implement. Perhaps a simple “x” in the top left corner.

xtho25 commented 1 month ago

So i actually coded a solution to this many days ago but just forgot to post it. It's not perfect but it works. Basically you have to click on the widget for it to get recognised by windows and show the app in the taskbar and then you can just click on the x button to close it.

This works using overlay_root.protocol("WM_DELETE_WINDOW", on_close) to customise what happens when the x button gets clicked. From there it's as simple as making the on_close function which should look something like this:

def on_close():
    close = messagebox.askokcancel("Close", "Would you like to close the program?")
    if close:
        overlay_root.destroy()
        os._exit(1)

I also added a custom messagebox to give a warning to the user which is entirely optional and doen't really need to exist. The reason why i dislike this option (and didn't make a pull request) is because initially you have to click on the window to get it recognised. The tk button by itself isn't a good option because if someone tries to click on the windows x button (using the taskbar and not the tk button) will cause the same issue of the window closing while leaving the program on. I believe that a small x button that can be turned on and off by a constant or an external config file paired with the code above can lead to a great solution. (ok wow that took too much time to write)