I created a simple program to convert video to audio, using the moviepy library and the program as follows:
import moviepy.editor as mp
from tkinter import *
from tkinter import ttk
from tkinter.filedialog import asksaveasfile, askopenfile
from tkinter.messagebox import showerror
def Open():
video_path = askopenfile(initialdir = "Video", title = "Open Video", filetypes = (("Video", "*.MP4;*.AVI;*.WAV;*.MKV;*.webm;*.TS;*.ASF;*OOG"), ("All files", "*.*")))
try:
open(video_path.name, "r")
ent_mp4.delete(0, END)
ent_mp4.insert(0, video_path.name)
except:
pass
def save_in():
if not(ent_mp4.get() == ""):
saveas = asksaveasfile(initialdir = "Music", title = "Save in", filetype = [("Aduio", "*.MP3;*.FLAC;*.CD;*.WMV"), ("All filest", "*.*")])
ent_mp3.delete(0, END)
ent_mp3.insert(0, saveas.name)
else:
showerror("Error: Empty Entry", "Pleas Enter Your Video Path")
def convert():
video = ent_mp4.get()
music = ent_mp3.get()
if not(music == ""):
root.destroy()
clip = mp.VideoFileClip(video)
clip.audio.write_audiofile(music)
main()
else:
showerror("Error: Empty Entry", "Pleas Enter Your Music Path")
ent_mp4, ent_mp3, root = None, None, None
bu1, bu2, bu3 = None, None, None
def main():
global ent_mp3, ent_mp4, root, bu1, bu2, bu3, sv
root = Tk()
root.title("Convert Video to Audio")
ent_mp4 = ttk.Entry(root, width = 50)
ent_mp4.grid(row = 0, column = 0)
ent_mp3 = ttk.Entry(root, width = 50)
ent_mp3.grid(row = 1, column = 0)
ttk.Button(root, text = "Open video", command = lambda: Open()).grid(row = 0, column = 1)
ttk.Button(root, text = "Save in", command = lambda: save_in()).grid(row = 1, column = 1)
f = ttk.Frame(root)
f.grid(row = 2, column = 0, columnspan = 2)
ttk.Button(f, text = "Convert", command = lambda: convert()).pack(side = LEFT)
ttk.Button(f, text = "Exit", command = lambda: exit()).pack(side = RIGHT)
root.mainloop()
main()
The program is successful but I just want to add something simple, which is that instead of removing the window when the root.destroy ()
switching process is running, an animated GIF is added that indicates that the process is in progress
I suspect that the solution is to apply two things at the same time for the process to succeed
But I didn't find how to try the "with" command but it didn't work out
So what is the solution