我的班级
class Mydb():
def __init__ (self):
self.conn = sqlite3.connect('C:\\lab\\pictures.db')
def queryf(self,q):
c = self.conn.cursor()
c.execute(q)
data = c.fetchone()
return data[0]
使用Mydb类
....
q = "SELECT file FROM t_pictures WHERE id = 1;"
db = Mydb()
_data = db.queryf(q)
start_image = wx.Image(_data)
start_image.Rescale(150, 100)
image = wx.BitmapFromImage(start_image)
self.bitmap_button_1 = wx.BitmapButton(self, wx.ID_ANY,image)
错误
TypeError: String or Unicode type required
答案 0 :(得分:1)
def Onbutton_1(self,event):
q = "SELECT file FROM t_pictures WHERE id = 1;"
db = Mydb()
_buffer = db.queryf(q)
stream = cStringIO.StringIO(_buffer)
image = wx.ImageFromStream(stream)
_pic = wx.BitmapFromImage(image.Rescale(150, 100))
self.bitmap_button_1 = wx.BitmapButton(self, wx.BITMAP_TYPE_ANY,_pic)
答案 1 :(得分:0)
数据库未从该查询返回字符串。您需要找出它返回的对象类型。我的猜测是你收到了一个元组。在这种情况下,从元组中提取字符串并尝试将其放入Image小部件中。还要确保将wx.BITMAP_TYPE_ANY作为第二个参数传递给wx.Image,以使窗口小部件更加灵活。有关详细信息,请参阅http://www.wxpython.org/docs/api/wx.Image-class.html。