0

I'm trying to make a video editor in Python and Tkinter and MoviePy, but it is showing some error

from moviepy.editor import *
from tkinter import *
from tkinter import filedialog

def browseFiles():
    global fn
    fn = filedialog.askopenfilename(initialdir = "/",
                                          title = "Select Video to",
                                          filetypes = (("Video Files",
                                                        "*.mp4*"),
                                                       ("All files",
                                                        "*.*")))

gui = Tk()

gui.title("Master Video Editor")

gui.geometry("720x480")

gui.resizable(False, False)

gui.after(1, lambda: gui.focus_force())

KoL = Label.configure(gui , text="File Opened: "+fn) #THE PROBLEM
KoL.pack()

# loading video dsa gfg intro video
clip = VideoFileClip(fn)
 
# clipping of the video
# getting video for only starting 10 seconds
clip = clip.subclip(0, 10)
 
# Reduce the audio volume (volume x 0.8)
clip = clip.volumex(1)

# User Input Text Here
def textclip():
    global textinput

    textinput = input.get(1.0, "end-1c")

button2 = Button(gui, text="Browse Files", command=browseFiles)
button2.place(x=70,y=100)

button = Button(gui, text="Add Text", command=textclip)
button.place(x=140,y=280)
 
# Generate a text clip
txt_clip = TextClip(textinput, fontsize = 70, color = 'white')
 
# setting position of text in the center and duration will be 10 seconds
txt_clip = txt_clip.set_pos('center').set_duration(10)
 
# Overlay the text clip on the first video clip
video = CompositeVideoClip([clip, txt_clip])
 
# showing video
video.ipython_display(width = 280)

gui.mainloop()

The error:-

KoL = Label.configure(gui , text="File Opened: "+fn) ^^ NameError: name 'fn' is not defined

Can you please tell how to fix as I do not see any problem.

Thank You!

THEOP05
  • 19
  • 6
  • Well, the error seems pretty clear. You are trying to use a variable named `fn` which doesn't have any value defined. Where do you think in the code you are giving `fn` its value? – matszwecja Sep 01 '23 at 11:48

1 Answers1

0

You have to declare fn outside the function first.

from moviepy.editor import *
from tkinter import *
from tkinter import filedialog

fn="" # Add here

def browseFiles():
    global fn
    fn = filedialog.askopenfilename(initialdir = "/",
                                          title = "Select Video to",
                                          filetypes = (("Video Files",
                                                        "*.mp4*"),
                                                       ("All files",
                                                        "*.*")))

gui = Tk()

gui.title("Master Video Editor")

gui.geometry("720x480")

gui.resizable(False, False)

gui.after(1, lambda: gui.focus_force())

KoL = Label.configure(gui , text="File Opened: "+fn) #THE PROBLEM
trabeast
  • 26
  • 3