如何使用 eyed3 将艺术品放入 Tkinter Image 中?
How to get artwork into Tkinter Image using eyed3?
类似这个问题:
我想将 .m4a
文件(类似于 `.mp3')中的音乐作品导入 Tkinter Image 以显示在标签上。
由于某些奇怪的原因,link 中的所有答案都使用:
import eyed3
但我必须使用
import eyeD3
要安装我必须使用:
sudo apt install python-eyed3
sudo apt install eyed3
我是 运行 Ubuntu 16.04.6 LTS,最迟到 2021 年,这意味着我正在使用 Python 2.7.12。我了解 eyeD3
或 eyed3
Python 3.5 版本中的语法和命名约定可能已更改,这是 Ubuntu 16.04.6 LTS 的另一个选项。我也在使用 Linux 内核 4.14.188
LTS,但我怀疑这是否重要。
注意: 今天早上我尝试从 Python 打来 ffmpeg
电话,将 .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()
在我的电脑上运行良好。
类似这个问题:
我想将 .m4a
文件(类似于 `.mp3')中的音乐作品导入 Tkinter Image 以显示在标签上。
由于某些奇怪的原因,link 中的所有答案都使用:
import eyed3
但我必须使用
import eyeD3
要安装我必须使用:
sudo apt install python-eyed3
sudo apt install eyed3
我是 运行 Ubuntu 16.04.6 LTS,最迟到 2021 年,这意味着我正在使用 Python 2.7.12。我了解 eyeD3
或 eyed3
Python 3.5 版本中的语法和命名约定可能已更改,这是 Ubuntu 16.04.6 LTS 的另一个选项。我也在使用 Linux 内核 4.14.188
LTS,但我怀疑这是否重要。
注意: 今天早上我尝试从 Python 打来 ffmpeg
电话,将 .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()
在我的电脑上运行良好。