0

I know TinyDB can't store images but you can store the image file path. I have done that and I want to make my application display an image when a button is clicked. I have successfully added the file path to the database and I have tested the output using print and the file path displays (so it is working to that extent). Also no error message come up. The function is as follows:

def showcar():
    getcar = cardb.get(where("img_id") == "1")
    img = Image.open("{car_img}".format(**getcar))
    pic = ImageTk.PhotoImage(img)
    lblimage.configure(image=pic)

When I click the button the function is assigned to, nothing happens. But when I use the exact same code out of the function like so:

getcar = cardb.get(where("img_id") == "1")
img = Image.open("{car_img}".format(**getcar))
pic = ImageTk.PhotoImage(img)

btnshow = Button(root, text="Show All", command=lambda: lblimage.configure(image=pic))

Then the image displays when the button is clicked. How can I make the application call the image path from TinyDB in a function?

RedCode
  • 363
  • 1
  • 6
  • 23
  • Possible duplicate of [Putting gif image in a canvas with Tkinter](https://stackoverflow.com/questions/16424091/putting-gif-image-in-a-canvas-with-tkinter) – Josselin May 29 '17 at 13:20
  • @Josselin My question is pertaining more along the lines of calling the file path from TinyDB in a function, and not about getting the image to appear in general. – RedCode May 29 '17 at 13:29
  • But in your `showcar()` function it really seems like `pic` is going to be garbage-collected :) – Josselin May 29 '17 at 20:11

0 Answers0