MySQL Blob ( Single )image in Tkinter



Here we are displaying one image by using button and by using label. The image data is taken from Blob column of MySQL table.

Read more on how to display all records ( with image ) by looping

Tkinter GUI application to add, display update and delete Blob column data with image of MySQL table

Displaying Data from MySQL table

We defined my_conn as connection objectCollect the data from student_profile table by using SQLALchemy.
my_conn = create_engine("mysql+mysqldb://userid:password@localhost/database_name")try:    my_row=my_conn.execute("SELECT id,student,profile_photo FROM student_profile WHERE id=1")    student = my_row.fetchone()
Here we used student to collect data. Here is the code to display student id and name.
# displaying student id on Button b1=tk.Button(my_w,text=student[0])b1.grid(row=1,column=1)# displaying student name over buttonb2=tk.Button(my_w,text=student[1])b2.grid(row=1,column=2)
Managing image display.
import iofrom PIL import Image, ImageTk
#collecting image and displaying img = Image.open(io.BytesIO(student[2]))img = ImageTk.PhotoImage(img)b2 =tk.Button(my_w,image=img) # using Button b2.grid(row=2,column=1)
l2 = tk.Label(my_w,image=img) # using Label l2.grid(row=2,column=2) 

Full code is here
import tkinter  as tk from tkinter import * import iofrom PIL import Image, ImageTkmy_w = tk.Tk()my_w.geometry("400x250") from sqlalchemy import create_enginefrom sqlalchemy.exc import SQLAlchemyErrormy_conn = create_engine("mysql+mysqldb://userid:password@localhost/database_name")try:    my_row=my_conn.execute("SELECT id,student,profile_photo FROM student_profile WHERE id=1")    student = my_row.fetchone()except SQLAlchemyError as e:  error=str(e.__dict__['orig'])  print(error) # displaying student id on Button b1=tk.Button(my_w,text=student[0])b1.grid(row=1,column=1)# displaying student name over buttonb2=tk.Button(my_w,text=student[1])b2.grid(row=1,column=2)#collecting image and displaying img = Image.open(io.BytesIO(student[2]))img = ImageTk.PhotoImage(img)b2 =tk.Button(my_w,image=img) # using Button b2.grid(row=2,column=1)l2 = tk.Label(my_w,image=img) # using Label l2.grid(row=2,column=2) my_w.mainloop()

Tkinter window to display MySQL Blob Data type image( All records)
Tkinter update Blob Data type with user uploaded image
Tkinter delete record with Blob Data type

Tkinter MySQL Record display MySQL Update MySQL Delete
Changes required for using SQLite database in place of MySQL
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer