Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Video in Canvas
#1
Hi, just wanted to know if its possible to play a video in canvas with tkinter?
"Only Boring People Get Bored"
Reply
#2
https://stackoverflow.com/q/7227162/4046632
https://github.com/PaulleDemon/tkVideoPlayer
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Thumbs Up 
(Sep-29-2022, 10:35 AM)buran Wrote: https://stackoverflow.com/q/7227162/4046632
https://github.com/PaulleDemon/tkVideoPlayer

Thanks Thumbs Up


I have this code below:

from tkinter import *
from tkinter.filedialog import askopenfile
from tkVideoPlayer import TkinterVideo
from random import *
 
window = Tk()
window.title("Tkinter Play Videos in Video Player")
window.geometry("700x450")
window.configure(bg="orange red")

canvas = Canvas(window, bg="green")
canvas.pack(expand=True, fill=BOTH)

def circle():
    x = randint(0, 299)
    y = randint(0, 299)
    diameter = randint(10, 100)
    circ = canvas.create_oval(x, y, x + diameter, y + diameter)
    canvas.tag_raise(circ)

b = Button(canvas, text="Circle", command=circle)
b.pack()
 
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(canvas, scaled=True)
        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()
    

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()
It puts a video in the canvas and plays it, what I want is when the circle button is pressed a circle will be placed on top of the video playing. However, it places the circle, but keeps it behind it. How can i fix this, I have tried canvas.tag_raise(circ), but have had no luck.
"Only Boring People Get Bored"
Reply
#4
You need to redraw the circle each time the video image changes. Since you can't do that with tkinter, you need to look at adding an overlay in the video player. Does TkinterVideo support that? I remember a post in the gui forum about someone doing video with an overlay using tkinter and cv2. Search for that.
Reply
#5
(Sep-29-2022, 02:11 PM)deanhystad Wrote: You need to redraw the circle each time the video image changes. Since you can't do that with tkinter, you need to look at adding an overlay in the video player. Does TkinterVideo support that? I remember a post in the gui forum about someone doing video with an overlay using tkinter and cv2. Search for that.

Okay ill have a look
"Only Boring People Get Bored"
Reply
#6
Quote: I have tried canvas.tag_raise(circ)
circ is a function not a tag, I believe that the video player isn't a canvas object so any ovals created would be under it on the canvas.
Reply
#7
(Oct-02-2022, 01:57 PM)joe_momma Wrote:
Quote: I have tried canvas.tag_raise(circ)
circ is a function not a tag, I believe that the video player isn't a canvas object so any ovals created would be under it on the canvas.

So how would i be able to get them to appear on top?
"Only Boring People Get Bored"
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Resizing image inside Canvas (with Canvas' resize) Gupi 2 25,126 Jun-04-2019, 05:05 AM
Last Post: Gupi
  [PyQt] Embedding a Video in Video Player WhatsupSmiley 0 5,914 Jan-28-2019, 06:24 PM
Last Post: WhatsupSmiley

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020