Dec-04-2022, 05:06 PM
Hi All,
I have the below code:
I have the below code:
from tkinter import *
from tkinter.filedialog import askopenfile
from tkVideoPlayer import TkinterVideo
from random import *
import cv2
from tkinter import messagebox
global closed
closed = 0
window = Tk()
window.title("Tkinter Play Videos in Video Player")
window.attributes('-fullscreen',True)
window.configure(bg="orange red")
#TODO: get video pushed to left without white
canvas = Canvas(window, bg="orange red")
canvas.pack(expand=True, fill=BOTH)
global next_coord
next_coord = False
def get_coords(event):
global next_coord
global coords_x_1
global coords_y_1
global coords_x_2
global coords_y_2
if next_coord == False:
coords_x_1 = event.x
coords_y_1 = event.y
print ((str(coords_x_1) + " " + str(coords_y_1)))
print ("above is 1")
next_coord = True
elif next_coord == True:
coords_x_2 = event.x
coords_y_2 = event.y
print ((str(coords_x_2) + " " + str(coords_y_2)))
print ("above is 2")
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=False)
videoplayer.bind("<Button-1>", get_coords)
videoplayer.load(r"{}".format(filename))
videoplayer.pack(side=LEFT, 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=BOTTOM, pady=2)
playbtn = Button(window, text='Play Video', command=lambda: playAgain())
playbtn.pack(side=BOTTOM, pady=3)
stopbtn = Button(window, text='Stop Video', command=lambda: StopVideo())
stopbtn.pack(side=BOTTOM, padx=4)
pausebtn = Button(window, text='Pause Video', command=lambda: PauseVideo())
pausebtn.pack(side=BOTTOM, padx=5)
def on_closing():
global closed
if messagebox.askokcancel("Quit", "Do you want to quit?"):
closed = 1
window.destroy()
window.protocol("WM_DELETE_WINDOW", on_closing)
window.mainloop()It allows me to upload a video, then it records the coords of where I click on the video. However, when I upload the video it puts it in the middle, and adds a white background around it. What can I do so it moves into the top left corner, and the white background is removed?
"Only Boring People Get Bored"
