0

I've been doing some application building with Tkinter and I've stumbled into a problem where closing the main Tk() window doesn't kill the underlying python shell. I soon realised that python-vlc was actually causing the program to wait until the song I put to play stopped.

I thought that simply placing and exit() or quit() after the root.mainloop() would suffice, but it doesn't seem to execute it after the window is closed, so I realised what I needed was a way for the Mediaplayer.stop() function to be called when the window is closed.

Note: Not my actual code, but an example of the behaviour

import vlc

class Manager():

    def __init__(self):

        self.root = Tk()

        self.song = vlc.Mediaplayer("Song.mp3")
        song.start()

        self.root.mainloop()

        print("Killing Program...")
        exit()

When self.root is closed:

Expected: Song Stops, python shell closes.

Observed: Song Plays for n seconds before python shell is closed.

NB: I am running the file as a .pyw file in the terminal, don't know if that affects anything, but I achieve the same effect when running in IDLE or in my IDE (Jupyter Lab).

DTheLegend
  • 11
  • 1
  • 4
  • You can override the exit protocol - read [this post](https://stackoverflow.com/questions/111155/how-do-i-handle-the-window-close-event-in-tkinter) for details. – Henry Yik Oct 06 '19 at 13:07
  • It's already discussed here: https://stackoverflow.com/questions/20039096/python-tkinter-check-if-root-has-been-destroyed – rizerphe Oct 18 '19 at 17:39
  • Does this answer your question? [python Tkinter, check if root has been destroyed?](https://stackoverflow.com/questions/20039096/python-tkinter-check-if-root-has-been-destroyed) – DTheLegend Dec 18 '19 at 19:49

0 Answers0