0

我知道 TinyDB 不能存储图像,但您可以存储图像文件路径。我已经做到了,我想让我的应用程序在单击按钮时显示图像。我已经成功地将文件路径添加到数据库中,并且我已经使用print和文件路径显示测试了输出(所以它在那个程度上工作)。也没有出现错误消息。功能如下:

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

当我单击分配功能的按钮时,没有任何反应。但是当我像这样在函数中使用完全相同的代码时:

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))

然后在单击按钮时显示图像。如何让应用程序在函数中调用 TinyDB 的图像路径?

4

0 回答 0