需求
我想从数据库中检索一张图片,并将这张图片设置给kivy的Image小部件,但该操作会引发ValueError错误,我不确定原因。欢迎任何建议。
数据库:Sqlite3
表名:Users
列名:UserID、UserName和UserImage
def populate_fields(self): # NEW
# Code retrieves text data and display in textinput fields here.
# STEP 1: RETRIEVE IMAGE
connection = sqlite3.connect("demo.db")
with connection:
cursor = connection.cursor()
cursor.execute("SELECT UserImage from Users where
UserID=?",self.data_items[columns[0]]['text'] )
image = cursor.fetchone()
data = io.BytesIO(image[0])
#STEP 2: SET OUTPUT TO IMAGE WIDGET
self.image.source = data # ---> triggers an Error
错误追踪:
self.image.source = data
File "kivy\weakproxy.pyx", line 33, in kivy.weakproxy.WeakProxy.__setattr__ (kivy\weakproxy.c:1471)
File "kivy\properties.pyx", line 478, in kivy.properties.Property.__set__ (kivy\properties.c:5572)
File "kivy\properties.pyx", line 513, in kivy.properties.Property.set (kivy\properties.c:6352)
File "kivy\properties.pyx", line 504, in kivy.properties.Property.set (kivy\properties.c:6173)
File "kivy\properties.pyx", line 676, in kivy.properties.StringProperty.check (kivy\properties.c:8613)
ValueError: Image.source accept only str