【问题标题】:How to use a video logo for the DearPyGUI?如何为 DearPyGUI 使用视频徽标?
【发布时间】:2021-05-25 16:30:59
【问题描述】:

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

谢谢!

【问题讨论】:

    标签: python user-interface video dearpygui


    【解决方案1】:

    我为此使用了 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()
    
    

    编辑:谢谢

    【讨论】:

    • 我什至在里面放了几行来确保你已经正确地使用 pip 安装了它:)
    • 感谢@nsde 提供如此丰富的答案!
    【解决方案2】:

    目前不支持 DearPyGui 中的视频

    【讨论】:

    • 请添加更多详细信息以扩展您的答案,例如工作代码或文档引用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 2018-04-07
    • 1970-01-01
    • 2017-12-16
    • 2013-11-28
    • 1970-01-01
    相关资源
    最近更新 更多