pythonuser-interfacevideodearpygui

How to use a video logo for the DearPyGUI?


I'm new to Python GUI's and am currently trying to build an app with DearPy. I was wondering if it's possible to use an mp4 formatted logo (animated logo) instead of the png logo's it would usually accept. For example:

with window("Appi", width= 520, height=677):
    print("GUI is running")
    set_window_pos("Appi", 0, 0)
    add_drawing("logo", width=520, height=290)

draw_image("logo", "random.png", [0,240])

My question is: would it be possible to change the add_drawing to an add video and then the draw_image to allow me to insert an mp4 instead of a png? I've tried to look through the documentation but haven't found guidance for this yet.

Or is there an alternative package I should be using (i.e. tkinter)?

Thanks!


Solution

  • I used tkinter for this and it worked perfectly fine:

    import tkinter as tk
    import threading
    import os
    import time
    
    try:
        import imageio
    except ModuleNotFoundError:
        os.system('pip install imageio')
        import imageio
    
    from PIL import Image, ImageTk
    
    # Settings:
    video_name = 'your_video_path_here.extension' #This is your video file path
    video_fps = 60
    
    video_fps = video_fps * 1.2 # because loading the frames might take some time
    
    try:
        video = imageio.get_reader(video_name)
    except:
        os.system('pip install imageio-ffmpeg')
        video = imageio.get_reader(video_name)
    
    def stream(label):
        '''Streams a video to a image label
        label: the label used to show the image
        '''
        for frame in video.iter_data():
            # render a frame
            frame_image = ImageTk.PhotoImage(Image.fromarray(frame))
            label.config(image=frame_image)
            label.image = frame_image
    
            time.sleep(1/video_fps) # wait
    
    # GUI
    
    root = tk.Tk()
    
    my_label = tk.Label(root)
    my_label.pack()
    
    thread = threading.Thread(target=stream, args=(my_label,))
    thread.daemon = 1
    thread.start()
    
    root.mainloop()
    
    

    Edit: Thanks <3