通常庫PIL的連接步驟如下:連接到PIL庫的替代方法?
from PIL import ImageTk, Image
我想這種方式連接它:
import PIL
,但我的版本無法正常工作。下面的代碼:
import os, sys
import tkinter
import PIL
main = tkinter.Tk()
catalogImg1 = 'imgs'
nameImg1 = 'n.jpg'
pathImg1 = os.path.join(catalogImg1, nameImg1)
openImg = PIL.Image.open(pathImg1)
renderImg = PIL.ImageTk.PhotoImage(openImg)
tkinter.Label(main, image=renderImg).pack()
main.mainloop()
的錯誤信息是:
Traceback (most recent call last): File "C:\Python33\projects\PIL_IMAGETK\ImageTK_photoimage - копия.py", line 11, in openImg = PIL.Image.open(pathImg1) AttributeError: 'module' object has no attribute 'Image'