python - 如何使用 eyed3 将艺术品放入 Tkinter Image?
问题描述
类似于这个问题:
我想将.m4a
文件(类似于“.mp3”)中的音乐作品放入 Tkinter Image 中,以便在标签上显示。
出于某种奇怪的原因,链接中的所有答案都使用:
import eyed3
但我必须使用
import eyeD3
安装我必须使用:
sudo apt install python-eyed3
sudo apt install eyed3
我最迟在 2021 年之前运行 Ubuntu 16.04.6 LTS,这意味着我使用的是 Python 2.7.12。我了解语法和命名约定可能在 Python 3.5 版本中发生了变化,eyeD3
这eyed3
是 Ubuntu 16.04.6 LTS 的另一个选项。我也在使用 Linux Kernel 4.14.188
LTS,但我怀疑这很重要。
注意:我ffmpeg
今天早上尝试从 Python 调用将.m4a
文件的艺术作品转换为.jpg
文件,但这很“复杂”,我希望eyed3
或者eyeD3
会更简单。
解决方案
使用file.tag.images
并迭代它,用于i.image_data
获取图像的字节数。
例如:
import eyed3, io
from PIL import Image, ImageTk
import tkinter as tk
root = tk.Tk()
file = eyed3.load(r"music_path")
# if there contains many images
for i in file.tag.images:
img = ImageTk.PhotoImage(Image.open(io.BytesIO(i.image_data)))
tk.Label(root, image=img).pack()
# or if there only one image here:
# img = ImageTk.PhotoImage(Image.open(io.BytesIO(file.tag.images[0].image_data)))
# tk.Label(root, image=img).pack()
root.mainloop()
推荐阅读
- javascript - React:getBoundingClientRect 获取先前渲染的位置
- python-3.x - 迭代读取excel工作表名称,将它们拆分并保存为Python中每个工作表的新列
- typescript - 记录在多个文件中出现的 ES 模块
- node.js - 将 Typescript 与 JSDoc 一起使用时,如何解决“找不到名称 'Record'”(或其他实用程序类型)?
- tabs - 如何在 Vue3 上制作最基本的路由器选项卡?
- c++ - 接受模板值参数或函数参数的函数模板
- jquery - 如何根据选择框的值制作所需的元素?表单验证.io
- javascript - JQuery 使用 .offset 向下滚动到 CSS 类 + 额外像素
- flutter - 参数类型'列表
>' 不能分配给参数类型 'List > - php - 如何在模型中从 Laravel / Eloquent 中的数组中转换数据