Skip to navigation
Simple wxpython dialog to update sqlite3 database
07.12.13
#!/usr/bin/env python import os import wx import sqlite3 class SetPasswordDialog(wx.Dialog): def __init__(self, parent, title): super(SetPasswordDialog, self).__init__(parent=parent, title=title,size=(300, 150)) #################################################### # Get Sqlite Data #################################################### con = sqlite3.connect("db/sad.db") e = con.cursor() e.execute("SELECT v FROM settings where id = '1'") user_name = e.fetchone()[0] p = con.cursor() p.execute("SELECT v FROM settings where id = '2'") password = p.fetchone()[0] panel = wx.Panel(self) hbox = wx.BoxSizer(wx.HORIZONTAL) fgs = wx.FlexGridSizer(3, 2, 9, 25) user = wx.StaticText(panel, label="Username:") passw = wx.StaticText(panel, label="Password:") self.tc1 = wx.TextCtrl(panel,-1,user_name) self.tc2 = wx.TextCtrl(panel,-1,password) bntUpdate = wx.Button(panel, label="Update", size=(90, 28)) bntCancel = wx.Button(panel, label="Cancel", size=(90, 28)) fgs.AddMany([ (user), (self.tc1, 1, wx.EXPAND), (passw), (self.tc2, 1, wx.EXPAND), (bntUpdate),(bntCancel) ]) fgs.AddGrowableRow(2, 1) fgs.AddGrowableCol(1, 1) hbox.Add(fgs, proportion=1, flag=wx.ALL|wx.EXPAND, border=15) bntUpdate.Bind(wx.EVT_BUTTON, self.OnUpdate) bntCancel.Bind(wx.EVT_BUTTON, self.OnCancel) panel.SetSizerAndFit(hbox) self.CenterOnParent() def OnCancel(self, e): self.Destroy() def OnUpdate(self, e): username = self.tc1.GetValue() password = self.tc2.GetValue() con = sqlite3.connect("db/sad.db") c = con.cursor() sql = "UPDATE settings SET v = '"+ username +"' WHERE id = 1" c.execute(sql) con.commit() c = con.cursor() sql = "UPDATE settings SET v = '"+ password +"' WHERE id = 2" c.execute(sql) con.commit() self.Destroy()
Reply
Anonymous
Information Epoch 1732501753
Avoid captive user interfaces.
Home
Notebook
Contact us