Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/08/2011, 14:21
Avatar de bosterkill
bosterkill
 
Fecha de Ingreso: mayo-2011
Mensajes: 56
Antigüedad: 13 años
Puntos: 0
Pregunta problema reflejar datos query en wx.textctrl

Hola, al fin pude hacer una consulta sqlite con interface wxpython pero mi problema actual es que la consulta me la refleja en un cuadro "wxpython: stdout/stderr" y yo lo unico que deseo es reflejar el dato de base de datos en una caja de texto.. me pueden ayudar??

supongo que es problema con el fetchall()

codigo

Código Python:
Ver original
  1. import wx
  2. import sqlite3 as lite
  3.  
  4. class InsertarDato(wx.Frame):
  5.     def __init__(self, parent, id, title):
  6.         self.con = lite.connect("MiBase.sqlite")
  7.         self.cur = self.con.cursor()
  8.        
  9.         wx.Frame.__init__(self, parent, id, title, size = (280, 200))
  10.        
  11.         panel = wx.Panel(self, -1)
  12.        
  13.                
  14.         gs = wx.FlexGridSizer(3, 2, 9, 9)
  15.         vbox = wx.BoxSizer(wx.VERTICAL)
  16.         hbox = wx.BoxSizer(wx.HORIZONTAL)
  17.        
  18.         codigo = wx.StaticText(panel, -1, "Codigo")
  19.         producto = wx.StaticText(panel, -1, "Producto")
  20.         costo = wx.StaticText(panel, -1, "Costo")
  21.         self.sp = wx.TextCtrl(panel, -1, "", size = (60, -1))
  22.         self.tc1 = wx.TextCtrl(panel, -1, size = (150, -1))
  23.         self.tc2 = wx.TextCtrl(panel, -1, size = (150, -1))
  24.        
  25.         gs.AddMany([(codigo), (self.tc1, 1, wx.LEFT, 10),
  26.                     (producto), (self.tc2, 1, wx.LEFT, 10),
  27.                     (costo), (self.sp, 0, wx.LEFT, 10)])
  28.        
  29.         vbox.Add(gs, 0, wx.ALL, 10)
  30.         vbox.Add((-1, 30))
  31.        
  32.         guardar = wx.Button(panel, -1, "Guardar", size = (-1, 30))
  33.         salir = wx.Button(panel, -1, "Salir", size = (-1, 30))
  34.         buscar = wx.Button(panel, -1, "Buscar", size = (-1, 30))
  35.         hbox.Add(guardar)
  36.         hbox.Add(salir, 0, wx.LEFT, 5)
  37.         hbox.Add(buscar, 0, wx.RIGHT, 5)
  38.         vbox.Add(hbox, 0, wx.ALIGN_CENTER | wx.BOTTOM, 10)
  39.        
  40.         self.Bind(wx.EVT_BUTTON, self.OnGuardar, id = guardar.GetId())
  41.         self.Bind(wx.EVT_BUTTON, self.OnSalir, id = salir.GetId())
  42.         self.Bind(wx.EVT_BUTTON, self.OnBuscar, id = buscar.GetId())
  43.        
  44.         panel.SetSizer(vbox)
  45.        
  46.         self.Centre()
  47.         self.Show(True)
  48.        
  49.                
  50.        
  51.     def OnGuardar(self, event):
  52.         try:
  53.             codigo = self.tc1.GetValue()
  54.             producto = self.tc2.GetValue()
  55.             costo = self.sp.GetValue()
  56.            
  57.             self.cur.execute("insert into inventario values (?, ?, ?)", (codigo, producto, costo))
  58.             self.con.commit()
  59.             self.tc1.Clear()
  60.             self.sp.Clear()
  61.             self.tc2.Clear()
  62.            
  63.         except lite.Error, error:
  64.             dlg = wx.MessageDialog(self, str(error), "Ha ocurrido un error")
  65.             dlg.ShowModal()
  66.            
  67.     def OnSalir(self, event):
  68.         self.Destroy()
  69.      
  70.     def OnBuscar(self, event):
  71.         self.tc1.GetValue()
  72.        
  73.         self.cur.execute("SELECT * FROM inventario WHERE codigo = %s" %self.tc1.GetValue())
  74.         self.tc1.Clear()
  75.         self.recs_list = self.cur.fetchall()
  76.         print self.recs_list
  77.        
  78.  
  79.        
  80.        
  81. app = wx.App()
  82. InsertarDato(None, -1, "Dialogo de Inventario")
  83. app.MainLoop()