[英]how do i display image stored in sqlite into tkinter window
this is the part that adds the image from an entry box into the database这是将图像从条目框中添加到数据库的部分
def add_img():
db=sq.connect('img.db')
conn=db.cursor()
with open(str(data.get()),'rb') as f:
file=f.read()
with open('yhu.png','wb') as p:
p.write(f)
conn.execute(''' INSERT INTO images(name,data)VALUES(?,?)''',(name,file))
db.commit()
db.close()
and this part is supposed to display the image into the tkiinter window这部分应该将图像显示到 tkiinter 窗口中
def display():
db=sq.connect('img.db')
conn=db.cursor()
conn.execute('''SELECT * FROM images''')
row=conn.fetchall()
for i in row:
it=i[1]
this= open(str(len(i[1])),'wb')
this.write(base64string.decode('base64'))
this.close
imgd=ImageTk.PhotoImage(this)
panel=tk.Label(image=imgd,height=28,width=30)
panel.image = imgd
panel.grid()
db.close()
The PhotoImage
class and can accept the binary data as a parameter without having to save it to a file: PhotoImage
类可以接受二进制数据作为参数,而无需将其保存到文件中:
imgd = ImageTk.PhotoImage(data=it)
The above assumes that it
is the binary data from the original image file.上面假设
it
是来自原始图像文件的二进制数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.