如何为DearPyGUI使用视频徽标?

2024-10-03 09:16:21 发布

您现在位置:Python中文网/ 问答频道 /正文

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

我的问题是:是否可以将“添加”图形更改为“添加视频”,然后更改“添加”图像以允许我插入mp4而不是png?我试着浏览文档,但还没有找到相关的指导

或者我是否应该使用其他软件包(即tkinter)

谢谢


Tags: 应用程序png格式withgui动画windowwidth
2条回答

当前不支持DearPyGui中的视频

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

编辑:谢谢<;三,

相关问题 更多 >