Download the zip file at the end of this tutorial with all source codes and sample images.
About MySQL table student_profile.
Our student_profile table has three columns,
id int(2) student varchar(10) profile_photo blob
This can be linked with our student table and photos of the student can be displayed.
Displaying record details with Photo
We defined my_connas connection object
Collect the data from student_profile table by using SQLALchemy.
my_conn = create_engine("mysql+mysqldb://userid:password@localhost/database_name")
my_row=my_conn.execute("SELECT * FROM student_profile limit 0,4")
for student in my_row:
pass
Here we used student to collect data.
student[0] -> id column ( int )
student[1] -> Name column ( varchar)
student[2] -> profile_photo ( Blob )
Here is the code to display student id and name.
e = Label(my_w, text=student[0])
e.grid(row=i,column=1,ipadx=20)
e = Label(my_w, text=student[1])
e.grid(row=i,column=2,ipadx=60)
In above code we will add one line images.append(img) to keep refrence to all images in a directory images[]. Without this line only the last image will be displayed. Here the image being used in the Button, or in a Label does not count as a reference for the garbage collector.