dropdown menu

Back To Home

Thursday, November 26, 2020

Solved: AttributeError_ type object 'Image' has no attribute 'open'

When we facing this issue, we need to add this module PIL.Image and use image=PIL.Image.open('/home/pi/Desktop/scene.jpg').


Code:

from tkinter import Tk, Canvas

from PIL import ImageTk, Image

from tkinter import *

import tkinter.font as tkFont

import PIL.Image   #Add this module

root = Tk()

topFrame =Frame(root,width=100,height=100)

topFrame.grid(row=1,column=0,rowspan=2)


def image1():

    print("hello")

#image=Image.open('/home/pi/Desktop/scene.jpg')    #comment out this

image=PIL.Image.open('/home/pi/Desktop/scene.jpg')   #use this 

photo = ImageTk.PhotoImage(image)

#a.config(image=mi,compound=BOTTOM)

a=Button(topFrame,image=photo,text="All stones preview",command=image1,height=290,width=335,font=tkFont.Font(weight="bold",size=15))

a.grid(row=1, column=1)

root.mainloop()


Video:



No comments:

Post a Comment