我有数据库包括名为(IMG)的BLOB列,当按代码搜索时,我需要什么,显示项目图像,但结果总是像这样(caV\xd6\xf7\xd0\xec]c\x1b\x95\xe2\xa4\x00\xe3\xd3\x82L\xc9L\xa2W8H\xaf\xe4\xe0\x9f\xcb\x7f\xb5\xbautm]\x94\'\xb6\xb7p\xa7{\xbffU\xb7Q\xd5\x8d\xe3\xe1\xb....等)
import io
import base64
from PyQt5 import QtGui
from ui import Ui_MainWindow
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import ast
import sqlite3
import sys
class HmcProject ( QMainWindow, Ui_MainWindow ): # ,FORM_CLASS
def __init__(self):
QMainWindow.__init__ ( self )
super ( HmcProject, self ).__init__ ()
self.setupUi ( self )
self.Handle_Buttons ()
self.Db_Connect ()
self.Image_Retrive()
def Db_Connect(self):
self.connection = sqlite3.connect ( 'deals_db.db' )
cursor = self.connection.cursor ()
def Handle_Buttons(self):
self.pushButton.clicked.connect(self.Image_Retrive)
def Image_Retrive(self):
try:
cursor = self.connection.cursor ()
itemsearch = self.lineEdit_Item_NameS_3.text ()
sql = ('''
SELECT IMG FROM deals_data
WHERE ITEM_CODE= ?
''')
cursor.execute ( sql,[(itemsearch)])
data = cursor.fetchone ()
print ( data [0])
pix= QPixmap.loadFromData(data[0])
self.label.setPixmap(pix)
except:
pass
def main():
app = QApplication ( sys.argv )
window = HmcProject ()
window.show ()
app.exec_ ()
if __name__ == '__main__':
main ()
汪汪一只猫
相关分类