Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can i display image from mysql to python gui ? #1088

Open
2020Yasir-Sahibzada opened this issue Jan 8, 2021 · 2 comments
Open

How can i display image from mysql to python gui ? #1088

2020Yasir-Sahibzada opened this issue Jan 8, 2021 · 2 comments

Comments

@2020Yasir-Sahibzada
Copy link

I am trying , like this :

from tkinter import *
from io import BytesIO
window= Tk()
db=MySQLdb.connect("localhost","root","??","??")
cursor=db.cursor()
sql= "SELECT LOGO FROM SYSTEMDETAILS" cursor.execute(sql)
logo=cursor.fetchone()
img = Image.open(BytesIO(logo))
phimg = ImageTk.PhotoImage(img)
panel = Label(window, image = phimg)
panel.pack()

When i run this, it show error in line 9 , it want logo as an object but in here its tuple

@somanyadav
Copy link

Hello @2020Yasir-Sahibzada,

I think you can try to access like this,

logo = cursor.fetchone()
img_data = logo[0]

And after that you can use the BytesIO class to wrap the image data,

img = Image.open(BytesIO(img_data))

@anuragdaksh7
Copy link

Hey @2020Yasir-Sahibzada I think you didn't included mysql imports for the code
adding them might solve your issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants