简体   繁体   English

我如何将存储在 sqlite 中的图像显示到 tkinter 窗口中

[英]how do i display image stored in sqlite into tkinter window

this is the part that adds the image from an entry box into the database这是将图像从条目框中添加到数据库的部分

def add_img():
    db=sq.connect('img.db')
    conn=db.cursor()

    with open(str(data.get()),'rb') as f:
        file=f.read()
    with open('yhu.png','wb') as p:
        p.write(f)
    conn.execute(''' INSERT INTO images(name,data)VALUES(?,?)''',(name,file))

    db.commit()
    db.close()

and this part is supposed to display the image into the tkiinter window这部分应该将图像显示到 tkiinter 窗口中

def display():
db=sq.connect('img.db')
conn=db.cursor()
conn.execute('''SELECT * FROM images''')
row=conn.fetchall()

for i in row:

    it=i[1]
    this= open(str(len(i[1])),'wb')
    this.write(base64string.decode('base64'))
    this.close
    imgd=ImageTk.PhotoImage(this)
    panel=tk.Label(image=imgd,height=28,width=30)
    panel.image = imgd
    panel.grid()


db.close()

The PhotoImage class and can accept the binary data as a parameter without having to save it to a file: PhotoImage类可以接受二进制数据作为参数,而无需将其保存到文件中:

imgd = ImageTk.PhotoImage(data=it)

The above assumes that it is the binary data from the original image file.上面假设it是来自原始图像文件的二进制数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在新的Tkinter窗口上显示字典 - How do i display dictionaries on new tkinter window 如何在Python Tkinter窗口中显示搜索结果 - how do i display search results in Python Tkinter window 如何在新的 Tkinter window 中显示导入的 dataframe? - How do i display imported dataframe in new Tkinter window? 如何将 JPEG 图像插入 python Tkinter 窗口? - How do I insert a JPEG image into a python Tkinter window? 我如何在 tkinter 的选项卡窗口上放置背景图像 - How do i place a background image on tab window in tkinter 如何在 Tkinter 中显示图像(来自 URL) - How do I display an Image (from URL) in Tkinter 如何让我的 tkinter 图像弹出不显示 tkinter 选项窗口 - How do I make my tkinter image pop not show the tkinter option window 如何从 Sqlite3 获取更新的行以在 Tkinter 中显示? - How do I get updated rows from Sqlite3 to display in Tkinter? 为什么我不能在 tkinter Toplevel() window 中显示图像? - Why can't I display an Image in a tkinter Toplevel() window? 如何使用上传按钮显示图像并使用 window 调整大小(动态)使用 Tkinter python 调整大小,我需要添加上传按钮 - How to display image with upload button in and resize it with window resize (Dynamically)with Tkinter python, I need to add upload button
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM