Answer the question
In order to leave comments, you need to log in
Why doesn't an image appear on a button created with tkinter in Python?
The create_albums function should iterate through all the image locations that are in the sqlite database, creating buttons with those images. But this does not happen, the buttons remain empty. I don't understand what is wrong?
from tkinter import *
from PIL import ImageTk
import sqlite3
root = Tk()
root.minsize(300,300)
con = sqlite3.connect('tagsdatabase.db')
cur = con.cursor()
def create_albums():
albums = []
for album_f in cur.execute('SELECT Cover_Path FROM covers_db'):
albums.append(album_f[0])
for album_s in albums:
image = ImageTk.PhotoImage(file = str(album_s))
album_button = Button(root,
image = image,
width = 120, height = 120,
command = lambda: print('click'))
album_button.pack()
create_albums()
root.mainloop()
Answer the question
In order to leave comments, you need to log in
Add album_button.image = image before placing the button
***
for album_s in albums:
image = ImageTk.PhotoImage(file = str(album_s))
album_button = Button(root,
image = image,
width = 120, height = 120,
command = lambda: print('click'))
album_button.image = image
album_button.pack()
create_albums()
***
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question