为了账号安全,请及时绑定邮箱和手机立即绑定

如何使用 eyed3 将艺术品放入 Tkinter Image 中?

如何使用 eyed3 将艺术品放入 Tkinter Image 中?

繁花如伊 2023-04-11 15:32:36
我想从文件.m4a(类似于“.mp3”)中获取音乐作品到 Tkinter 图像中,以便在标签上显示。出于某种奇怪的原因,链接中的所有答案都使用: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.188LTS,但我怀疑这是否重要。注意:我ffmpeg今天早上尝试从 Python 调用将.m4a文件的插图转换为.jpg文件,但这很“复杂”,我希望eyed3或者eyeD3会更简单。
查看完整描述

1 回答

?
噜噜哒

TA贡献1784条经验 获得超7个赞

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

在我的电脑上运行良好。

//img1.sycdn.imooc.com//64350e290001308006580678.jpg

查看完整回答
反对 回复 2023-04-11
  • 1 回答
  • 0 关注
  • 62 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信