用tkinter可以显示jpg图片吗?

codesnail 2010-09-16 11:20:23
是不是只能显示gif和bmp?
...全文
643 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
luotuo512 2010-09-16
  • 打赏
  • 举报
回复
If you need to work with other file formats, the Python Imaging Library (PIL) contains classes that lets you load images in over 30 formats, and convert them to Tkinter-compatible image objects:

from PIL import Image, ImageTk

image = Image.open("lenna.jpg")
photo = ImageTk.PhotoImage(image)
You can use a PhotoImage instance everywhere Tkinter accepts an image object. An example:

label = Label(image=photo)
label.image = photo # keep a reference!
label.pack()
You must keep a reference to the image object in your Python program, either by storing it in a global variable, or by attaching it to another object.

网站:http://effbot.org/tkinterbook/photoimage.htm
codesnail 2010-09-16
  • 打赏
  • 举报
回复
另:您给的网址打不开。
codesnail 2010-09-16
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 luotuo512 的回复:]
from PIL import Image, ImageTk

image = Image.open("lenna.jpg")
photo = ImageTk.PhotoImage(image)
参见http://effbot.org.sixxs.org/tkinterbook/photoimage.htm
[/Quote]
这个我知道,但是photo.show()居然是调用系统的看图程序,,我晕。
我想怎么在程序窗口中显示jpg
luotuo512 2010-09-16
  • 打赏
  • 举报
回复
from PIL import Image, ImageTk

image = Image.open("lenna.jpg")
photo = ImageTk.PhotoImage(image)
参见http://effbot.org.sixxs.org/tkinterbook/photoimage.htm

37,738

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧