|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
代码:
from tkinter import * 报错:Traceback (most recent call last):
File "C:\Users\36181\Desktop\tk22.py", line 8, in <module>
root = Tk() photo = PhotoImage(file = "600.gif")
File "E:\Program Files (x86)\Python38-32\lib\tkinter\__init__.py", line 4061, in __init__
textLabel = Label(root,text = '网站可能含有猫的图片例如:') Image.__init__(self, 'photo', name, cnf, master, **kw)
textLabel.pack(side = LEFT) File "E:\Program Files (x86)\Python38-32\lib\tkinter\__init__.py", line 4006, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
photo = PhotoImage(file = "600.gif") _tkinter.TclError: couldn't recognize data in image file "600.gif"root = Tk()
# 另安装了 p i l l o w 显示图片还是报错
imgLabel = Label(root,image = photo) # 600.gif和tkinter显示这个图片的py都在桌面和同一个路径
imgLabel.pack(side = RIGHT)
mainloop()
先安装 Pillow,然后再将代码改成下面这样:
- from tkinter import *
- from PIL import ImageTk
-
- root = Tk()
-
- textLabel = Label(root,text = '网站可能含有猫的图片例如:')
- textLabel.pack(side = LEFT)
-
- photo = ImageTk.PhotoImage(file = "600.gif")
-
- imgLabel = Label(root,image = photo)
- imgLabel.pack(side = RIGHT)
- mainloop()
复制代码
|
|