首页 > 解决方案 > 如何为 DearPyGUI 使用视频徽标?

问题描述

我是 Python GUI 的新手,目前正在尝试使用 DearPy 构建一个应用程序。我想知道是否可以使用 mp4 格式的徽标(动画徽标)而不是通常接受的 png 徽标。例如:

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])

我的问题是:是否可以将 add_drawing 更改为添加视频,然后将 draw_image 更改为允许我插入 mp4 而不是 png?我试图查看文档,但还没有找到这方面的指导。

或者是否有我应该使用的替代包(即 tkinter)?

谢谢!

标签: pythonuser-interfacevideodearpygui

解决方案


我为此使用了 tkinter,它工作得非常好:

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()

编辑:谢谢<3


推荐阅读