Skip to content
Advertisement

Its giving me a module not found error but its installed but if i run a different code it does not give a error

When I run this code it gives a module not found error for line 2 but it is installed on my computer. I know that because when i type pip list in the command prompt it is in the list

from tkinter import *
from tkvideoplayer import TkinterVideo
from tkinter.filedialog import askopenfile
window = Tk()
window.title("My Video Player")
window.geometry("500x500")
window.config(bg="Turquoise")
heading = Label(window, text="My Video Player", bg="Orange Red", fg="white", font="4 none bold")
heading.config(anchor=CENTER)


def openFile():
    file = askopenfile(mode="r", filetypes=[('Video Files', '*.mp4', '*.mov')])
    if file is not None:
        global filename
        filename = file.name
        global videoPlayer
        videoPlayer = TkinterVideo(master=window, scaled=True, pre_load=False)
        videoPlayer.load(r"{}".format(filename))
        videoPlayer.pack(expand=True, fill="both")
        videoPlayer.play()


def playFile():
    videoPlayer.play()


def stopFile():
    videoPlayer.stop()


def pauseFile():
    videoPlayer.pause()


openbtn = Button(window, text="Open", command=lambda: openFile())
stopbtn = Button(window, text="Stop", command=lambda: stopFile())
playbtn = Button(window, text="Play", command=lambda: playFile())
pausebtn = Button(window, text="Pause", command=lambda: pauseFile())

openbtn.pack(side=TOP, pady=2)
stopbtn.pack(side=TOP, pady=4)
playbtn.pack(side=TOP, pady=3)
pausebtn.pack(side=TOP, pady=5)
heading.pack()

window.mainloop()

However on the same computer if I run this code

import datetime
import tkinter as tk
from tkinter import filedialog
from tkVideoPlayer import TkinterVideo


def update_duration(event):
    """ updates the duration after finding the duration """
    end_time["text"] = str(datetime.timedelta(seconds=vid_player.duration()))
    progress_slider["to"] = vid_player.duration()


def update_scale(event):
    """ updates the scale value """
    progress_slider.set(vid_player.current_duration())


def load_video():
    """ loads the video """
    file_path = filedialog.askopenfilename()

    if file_path:
        vid_player.load(file_path)

        progress_slider.config(to=0, from_=0)
        progress_slider.set(0)
        play_pause_btn["text"] = "Play"


def seek(value):
    """ used to seek a specific timeframe """
    vid_player.seek(int(value))


def skip(value: int):
    """ skip seconds """
    vid_player.skip_sec(value)
    progress_slider.set(progress_slider.get() + value)


def play_pause():
    """ pauses and plays """
    if vid_player.is_paused():
        vid_player.play()
        play_pause_btn["text"] = "Pause"

    else:
        vid_player.pause()
        play_pause_btn["text"] = "Play"


def video_ended(event):
    """ handle video ended """
    progress_slider.set(progress_slider["to"])
    play_pause_btn["text"] = "Play"


root = tk.Tk()
root.title("Video Player")
root.geometry("700x600")

load_btn = tk.Button(root, text="Load", command=load_video)
load_btn.pack()

vid_player = TkinterVideo(scaled=True, pre_load=False, master=root)
vid_player.pack(expand=True, fill="both")

play_pause_btn = tk.Button(root, text="Play", command=play_pause)
play_pause_btn.pack()

skip_plus_5sec = tk.Button(root, text="Skip -5 sec", command=lambda: skip(-5))
skip_plus_5sec.pack(side="left")

start_time = tk.Label(root, text=str(datetime.timedelta(seconds=0)))
start_time.pack(side="left")

progress_slider = tk.Scale(root, from_=0, to=0, orient="horizontal", command=seek)
progress_slider.pack(side="left", fill="x", expand=True)

end_time = tk.Label(root, text=str(datetime.timedelta(seconds=0)))
end_time.pack(side="left")

vid_player.bind("<<Duration>>", update_duration)
vid_player.bind("<<SecondChanged>>", update_scale)
vid_player.bind("<<Ended>>", video_ended)

skip_plus_5sec = tk.Button(root, text="Skip +5 sec", command=lambda: skip(5))
skip_plus_5sec.pack(side="left")

root.mainloop()

It works and does not give an error. But I am using the same code line. Can anyone explain that?

Advertisement

Answer

But I am using the same code line.

No, you’re not. The working version spells tkVideoPlayer in camelCase (and indeed, according to the package’s docs that’s the correct casing):

from tkVideoPlayer import TkinterVideo

and the version that doesn’t work spells it in all lowercase.

from tkvideoplayer import TkinterVideo

You’ll have to be careful about character case; in general programming languages and environments aren’t forgiving about that.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement