使用Tkinter从Mysql数据库检索并显示BLOB图像 [英] Retrieve and displaying BLOB images from Mysql database with Tkinter

查看:200
本文介绍了使用Tkinter从Mysql数据库检索并显示BLOB图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此def应该连接到数据库,并且如果参数正确,则应该检索BLOB图像,但是我对如何显示该图像感到困惑.当前,它将显示除我要显示的BLOB图像以外的所有其他信息.我意识到将其设置为stringvar是不正确的.任何人都可以帮助您澄清如何在Tkinter中显示它吗?如果没有,是否有其他解决方案?

this def should connect to a database, and if the parameters are correct should retrieve a BLOB image, however i confused on how to display that image. currently, it will display all the other information besides the BLOB image that i want to be displayed. i realize that setting it to a stringvar is not correct. can anyone help with some clarity on how to get this to display in Tkinter? if not, is there any alternative solutions?

func = Tkinter.Toplevel()
func.title("blah")
func.geometry('400x400+0+0)

db = MySQLdb.connect(host='xxx.xxx.xxx.xxx', user='xxx',passwd='xxxx',db='xxxxx')
cursor = db.cursor()

FirstName = QE1.get()
LastName = QE2.get()
SSN = QE3.get()

cursor execute ("""SELECT pat_face FROM PATIENT WHERE pat_firstname=%s AND pat_lastname=%s AND pat_id=%s""",(FirstName,LastName,SSN))

PATFACEresults = StringVar()
PATFACEresults.set(cursor.fetchone())

db.close()

PATFACE = Tkinter.Label(func, textvariable=PATFACEresults).grid(row=0,column=1)

推荐答案

我认为您需要为此使用PIL(可能还需要StringIO).

I think you'll need PIL for this (and possibly StringIO as well).

类似:

from PIL import Image, ImageTk
import cStringIO

...

results = cursor.fetchone()
data = cStringIO.StringIO(results.tostring())
pic = ImageTk.PhotoImage(Image.open(data))

patface = Tkinter.Label(func, image=pic)
patface.grid(row=0, column=1)

您还可以尝试将图像直接保存到文件&从那里加载它.

You could also try saving the image direct to a file & loading it from there.

更多信息:

  • http://zetcode.com/databases/mysqlpythontutorial/
  • http://www.effbot.org/zone/pil-index.htm
  • http://www.effbot.org/tkinterbook/

这篇关于使用Tkinter从Mysql数据库检索并显示BLOB图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆