如何使用python PIL

时间:2018-12-15 11:18:13

标签: python python-imaging-library

我正在尝试编写代码,以便使用sqlite3数据库和tkinter GUI将数据导入数据库来完成注册系统和身份证打印机的第一个表格。此表格用于从数据库获取数据并将该数据文本写入png图像。写入数据后的png图像是身份证。

**这就是问题..代码运行没有任何错误。但是图像未写入数据。首先尝试使用此代码,我没有使用数据库数据。我使用了来自字符串变量**的数据

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

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 = "Hello World"
  font = ImageFont.truetype("arial.ttf",200)
  w,h = font.getsize(str01)
  print(str01)

draw = ImageDraw.Draw(img)
draw.text(((900-w)/2,(900-h)/2),str01,font = font,fill = "black")
img.show()


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

canvas.pack()
tao.mainloop()

0 个答案:

没有答案