属性错误:类型对象“图像”没有属性“打开”

Tao*_*nga 3 python python-imaging-library

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'
Run Code Online (Sandbox Code Playgroud)

当我运行代码时出现此错误消息,我正在尝试编写注册系统和身份证打印机第一个表单,并使用 sqlite3 数据库和 tkinter GUI 将数据导入数据库。此表单用于从数据库获取数据并在照片上写入data.制作身份证并打印它。但是当我尝试使用 Image.Open() 打开图像文件时,它不起作用。

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()
Run Code Online (Sandbox Code Playgroud)

Ali*_*leh 6

问题是import *它与 混淆PIL.Imagetkinter.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()
Run Code Online (Sandbox Code Playgroud)