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).