I have a program, and I want it to play loading music, but stop after it's done.
I was thinking about this in another thread (multi-threading):
while True:
if Variables.StopMusic:
return
else:
playsound("blah.mp3", block=True)
But this would only run every time the music ends, so it wouldn't work right.
Here's my current code.
def commence():
global photo #This is necessary because https://stackoverflow.com/a/16424553/9654083
#AKA, It prevents the image from getting garbage collected
mbox.showinfo("Commencing download...","Press OK to start...")
url = Widgets.video.get()
if url == "":
mbox.showerror("Error", "Next time please type a URL.")
load = Toplevel(window)
load.geometry("1000x1000")
photo = getPhoto(load)
if Variables.audioSelect.get():
playsound("/usr/share/youtube-dl-gui/loading_music.mp3", block=False)
termf = Frame(load, height=50, width=200)
termf.pack(side="bottom", fill="both", expand=YES) #https://stackoverflow.com/questions/37017472/python-tkinter-place-put-frame-to-the-bottom
wid = termf.winfo_id()
try:
Popen(['xterm -into %d -geometry 200x50 -sb -e /bin/sh -c "youtube-dl %s;sleep 1;exit"' % (wid, url)], stdout=sstdout, stderr=sstdout, shell=True)
except Exception as ename:
mbox.showerror("ERROR!", "An error occured.")
print(ename)
class Variables:
audioSelect = IntVar()
audioSelect.set(1)
class Widgets:
video = Entry(window)
text = Label(text="Please insert a URL.")
audio = Checkbutton(variable=Variables.audioSelect, onvalue=True, offvalue=False, text="Add loading music?") #https://stackoverflow.com/a/16285194/9654083
Widgets.text.pack()
Widgets.video.pack()
Widgets.audio.pack()
Button(window, text="OK", command=commence).pack()
window.mainloop()
Is there anything like killing a function in python?