在python中显示jpg图像 [英] Display jpg images in python

查看:93
本文介绍了在python中显示jpg图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个简单的工具来将专辑封面图片添加到 python 中的 mp3 文件中.到目前为止,我只是在向亚马逊发送带有艺术家和专辑标题的请求,并获取结果列表,以及为每个结果查找实际图像.我想要做的是显示一个简单的框架,每个图像都有一个按钮/链接,还有一个跳过/取消按钮.

I am creating a simple tool to add album cover images to mp3 files in python. So far I am just working on sending a request to amazon with artist and album title, and get the resulting list, as well as finding the actual images for each result. What I want to do is to display a simple frame with a button/link for each image, and a skip/cancel button.

我已经用谷歌搜索了一些,但找不到可以用作基础的示例.

I have done some googling, but I can't find examples that I can use as a base.

  1. 我想直接显示来自网络的图像.IE.使用 urllib 打开并将字节读入内存,而不是通过磁盘上的文件
  2. 我想最好将图像显示为按钮

所有示例似乎都专注于处理磁盘上的文件,而不仅仅是一个缓冲区.python 标准库中的 TK 文档似乎没有涵盖基本的 Button 小部件.这似乎是一项简单的任务,我还没有找到合适的文档.

All examples seems to focus on working on files on disk, rather with just a buffer. The TK documentation in the python standard library doesn't seem to cover the basic Button widget. This seems like an easy task, I have just not had any luck in finding the proper documentation yet.

推荐答案

你可以修改this 使用 urllib.urlopen().但是我不知道(因为我还没有测试过)是否可以在不将(图像)文件保存在本地的情况下执行此步骤.但恕我直言 urlopen 返回一个在 tk.PhotoImage() 中可用的文件句柄.

you can modify this using urllib.urlopen(). But I don't know (as I haven't tested it) if you can make this step without saving the (image) file locally. But IMHO urlopen returns a file handle that is usable in tk.PhotoImage().

对于 PhotoImage 中的 jpg 文件,您需要 PIL:

For jpg files in PhotoImage you need PIL:

from PIL import Image, ImageTk
image = Image.open("test.jpg")
photo = ImageTk.PhotoImage(image)

这篇关于在python中显示jpg图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆