3
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1482, in __call__
return self.func(*args)
File "C:\Users\TAO\Desktop\New\b.py", line 14, in imgs
img = Image.open("C:\\Users\\TAO\\Desktop\\New\\02.png")
AttributeError: type object 'Image' has no attribute 'open'

this error message come when i run my code i am trying to code for make a registration System and Identity Card printer first form done with making data import to database using sqlite3 database and tkinter GUI.this form for get data from database and write on photo data.make the identity Card and print it.but when i trying to open image file with Image.Open() it is not working.

from PIL import *
import sqlite3
from tkinter import *

connection = sqlite3.connect("school.db")

tao = Tk()
tao.title("Mayurapada Central Collage")
tao.configure(bg = '#6699ff')
canvas = Canvas(tao,width = 600,height = 400,bg = '#6699ff')

def imgs():

    img = Image.open("C:\\Users\\TAO\\Desktop\\New\\02.png")
    img.show()
    str01 = "Image"
    font = ImageFont.truetype("arial.ttf",75)
    w,h = font.getsize(str01)
    print(str01)


button01 = Button(tao,text = "Preview",bd = 7,padx = 5,pady = 5,command = 
imgs).place(x = 50,y = 300)

canvas.pack()

tao.mainloop()

1 Answer 1

6

Problem is with import * it confuses PIL.Image with tkinter.Image.

import sqlite3
from tkinter import Tk, Button, Canvas
from PIL import Image, ImageFont

connection = sqlite3.connect("school.db")

tao = Tk()
tao.title("Mayurapada Central Collage")
tao.configure(bg = '#6699ff')
canvas = Canvas(tao,width = 600,height = 400,bg = '#6699ff')

def imgs():

    img = Image.open("C:\\Users\\TAO\\Desktop\\New\\02.png")
    img.show()
    str01 = "Image"
    font = ImageFont.truetype("arial.ttf",75)
    w,h = font.getsize(str01)
    print(str01)


button01 = Button(tao,text = "Preview",bd = 7,padx = 5,pady = 5,command = 
imgs).place(x = 50,y = 300)

canvas.pack()

tao.mainloop()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.