In this tutorial, you will learn how to use the tkvideoplayer
library with Python to create an advanced MP4 video player desktop application. Our video player will have all the required GUI controls to open an mp4 file, play, pause, and stop the video.
pip install tkvideoplayer
import tkinter as tk from tkVideoPlayer import TkinterVideo root = tk.Tk() videoplayer = TkinterVideo(master=root, scaled=True, pre_load=False) videoplayer.load(r"samplevideo.mp4") videoplayer.pack(expand=True, fill="both") videoplayer.play() # play the video root.mainloop()
from tkinter import * from tkinter.filedialog import askopenfile from tkVideoPlayer import TkinterVideo window = Tk() window.title("Tkinter Play Videos in Video Player") window.geometry("700x450") window.configure(bg="orange red") def open_file(): file = askopenfile(mode='r', filetypes=[ ('Video Files', ["*.mp4"])]) 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 playAgain(): print(filename) videoplayer.play() def StopVideo(): print(filename) videoplayer.stop() def PauseVideo(): print(filename) videoplayer.pause() # center this label lbl1 = Label(window, text="Tkinter Video Player", bg="orange red", fg="white", font="none 24 bold") lbl1.config(anchor=CENTER) lbl1.pack() openbtn = Button(window, text='Open', command=lambda: open_file()) openbtn.pack(side=TOP, pady=2) playbtn = Button(window, text='Play Video', command=lambda: playAgain()) playbtn.pack(side=TOP, pady=3) stopbtn = Button(window, text='Stop Video', command=lambda: StopVideo()) stopbtn.pack(side=TOP, padx=4) pausebtn = Button(window, text='Pause Video', command=lambda: PauseVideo()) pausebtn.pack(side=TOP, padx=5) window.mainloop()
We evaluated the performance of Llama 3.1 vs GPT-4 models on over 150 benchmark datasets…
The manufacturing industry is undergoing a significant transformation with the advent of Industrial IoT Solutions.…
If you're reading this, you must have heard the buzz about ChatGPT and its incredible…
How to Use ChatGPT in Cybersecurity If you're a cybersecurity geek, you've probably heard about…
Introduction In the dynamic world of cryptocurrencies, staying informed about the latest market trends is…
The Events Calendar Widgets for Elementor has become easiest solution for managing events on WordPress…