Ver Mensaje Individual
  #2 (permalink)  
Antiguo 01/08/2011, 16:53
Avatar de razpeitia
razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 2 meses
Puntos: 1360
Respuesta: problema reflejar datos query en wx.textctrl

En la linea 76 de tu código de arriba. Estas imprimiendo la lista de resultados. Por eso te manda el dialogo de stdout/stderr.

Ahora, no se como planeas desplegar la información. Te sugiero que uses un ListCtrl y un TextCtrl para hacer una ventana de búsqueda. Algo mas o menos parecido a esto.

Código Python:
Ver original
  1. import wx
  2. import sqlite3
  3.  
  4. class MyFrame(wx.Frame):
  5.     def __init__(self, *args, **kwargs):
  6.         wx.Frame.__init__(self, *args, **kwargs)
  7.         self.panel = MyPanel(self)
  8.        
  9. class MyPanel(wx.Panel):
  10.     def __init__(self, *args, **kwargs):
  11.         wx.Panel.__init__(self, *args, **kwargs)
  12.        
  13.         self.con = sqlite3.connect("MiBase.sqlite")
  14.         self.cur = self.con.cursor()
  15.        
  16.         hbox = wx.BoxSizer(wx.HORIZONTAL)
  17.         box = wx.BoxSizer(wx.VERTICAL)
  18.        
  19.         self.list = wx.ListCtrl(self, -1, style=wx.LC_REPORT|wx.SUNKEN_BORDER)
  20.         self.list.InsertColumn(0, "Codigo")
  21.         self.list.InsertColumn(1, "Producto")
  22.         self.list.InsertColumn(2, "Costo")
  23.        
  24.        
  25.         self.text = wx.TextCtrl(self, -1, size=wx.Size(300, -1))
  26.        
  27.         self.button = wx.Button(self, -1, "Buscar")
  28.         self.button.Bind(wx.EVT_BUTTON, self.onClick)
  29.        
  30.         hbox.Add(self.text, 0)
  31.         hbox.Add(self.button, 0)
  32.        
  33.         box.Add(hbox, 0)
  34.         box.Add(self.list, 1, wx.EXPAND)
  35.        
  36.         self.SetSizer(box)
  37.         self.Center()
  38.        
  39.         self.text.SetFocus()
  40.            
  41.     def onClick(self, event):
  42.         self.cur.execute("SELECT codigo, producto, costo FROM inventario WHERE codigo = ?" , (self.text.GetValue(), ))
  43.         recs_list = self.cur.fetchall()
  44.         self.list.DeleteAllItems()
  45.        
  46.         for row in recs_list:
  47.             pos = self.list.InsertStringItem(0, str(row[0]))
  48.             self.list.SetStringItem(pos, 1, str(row[1]))
  49.             self.list.SetStringItem(pos, 2, str(row[2]))
  50.        
  51. class MyApp(wx.App):
  52.     def OnInit(self):
  53.         frame = MyFrame(None, -1, "ListCtrl")
  54.         frame.Show(True)
  55.         self.SetTopWindow(frame)
  56.         return True
  57.  
  58. app = MyApp(0)
  59. app.MainLoop()