I want to list my bank in listctrl, but give this error, can anyone help me?
I've tried only that which is what I know, I could not find information on how to correct the error.
import wx
import sqlite3
class MyForm(wx.Frame):
db_name = 'banco.db'
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "List Control Tutorial")
# Add a panel so it looks the correct on all platforms
panel = wx.Panel(self, wx.ID_ANY)
self.index = 0
self.list_ctrl = wx.ListCtrl(panel, size=(-1,100),
style=wx.LC_REPORT
|wx.BORDER_SUNKEN
)
self.list_ctrl.InsertColumn(0, 'User')
self.list_ctrl.InsertColumn(1, 'Senha')
#self.list_ctrl.InsertColumn(2, 'Location', width=125)
#btn = wx.Button(panel, label="Add Line")
#btn2 = wx.Button(panel, label="Get Data")
#btn.Bind(wx.EVT_BUTTON, self.add_line)
#btn2.Bind(wx.EVT_BUTTON, self.get_data)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.list_ctrl, 0, wx.ALL|wx.EXPAND, 5)
#sizer.Add(btn, 0, wx.ALL|wx.CENTER, 5)
#sizer.Add(btn2, 0, wx.ALL|wx.CENTER, 5)
panel.SetSizer(sizer)
self.get_users()
def run_query (self, query, parameters=()):
with sqlite3.connect(self.db_name) as conn:
cursor = conn.cursor()
result = cursor.execute(query, parameters)
conn.commit()
return result
def get_users(self):
# Analisando dados
query = 'SELECT * FROM users'
db_rows= self.run_query(query)
# Preenchimento de dados
for row in db_rows:
self.list_ctrl.InsertItem(row[0],row[1],row[2])
# Run the program
if __name__ == "__main__":
app = wx.App(False)
frame = MyForm()
frame.Show()
app.MainLoop()
I hope someone can help me, because I do not know what else to do.
You almost certainly, in this case, want ListCtrl.Append()
.
As in:
self.list_ctrl.Append((row[0],row[1]))