python - 如何为 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)?
谢谢!
解决方案
我为此使用了 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
推荐阅读
- regex - 重新排列每个文件中的命名空间声明
- c# - Autofac - 装饰来自特定装配的所有组件
- python - 如何使 setsockopt IP_ADD_MEMBERSHIP 尊重本地接口地址以仅在一个特定接口上接收多播数据包?
- javascript - 单击href链接时如何将查询字符串参数添加到相同的URL
- c - 有没有比使用 sscanf 更好的方法来实现这个结果?
- command-prompt - Script-Fu 从 Windows 命令行误解文件名
- asp.net-core - EF Core 2.2:迁移开始报告上下文有待处理的模型更改
- haskell - 对由一个列表组成的自身类型的列表操作
- java - 如何在 Java 中使用 PrintStream 时找出发生的异常
- python - 在 Python 中从磁盘读取复杂数据结构的最快方法