Search code examples
pythontkintervideobackground

Is it possible to make a video background in Tkinker?


I'm very new to Tkinker and I'm trying to learn about it, but my plan would be to make a window with a video as a background and labels and buttons on top.

I've been looking about it for hours but I honestly don't know if it is possible or not... Is it possible?


Solution

  • You can use tkVideo to show a video in tkinter.

    You need to create a label to be the parent of a tkvideo object.

    import tkinter as tk
    from tkvideo import tkvideo
    
    root = tk.Tk()
    lbl = tk.Label(root)
    player = tkvideo("Your\\path\\here", lbl, loop=1) # loops infinitely
    player.play()
    lbl.pack()
    
    root.mainloop()
    

    If you want the video to be played at the background you can create a parent frame and then add things to the frame:

    import tkinter as tk
    from tkvideo import tkvideo
    
    root = tk.Tk()
    frame = tk.Frame(root)
    lbl = tk.Label(frame)
    player = tkvideo("Your Path here", lbl, loop=1)
    player.play()
    lbl.grid(row=0, column=0)
    
    button = tk.Button(frame, text="Click Me")
    button.grid(row=0, column=0)
    
    frame.pack()
    
    root.mainloop()