Still back to the same problem as before, cannot insert row data:
import wx
import mysql.connector
cnx = None
class MyForm(wx.Frame):
index = 0
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, title = 'My Form')
self.panel = wx.Panel(self, wx.ID_ANY)
self.bmp1 = wx.ArtProvider.GetBitmap(wx.ART_INFORMATION, wx.ART_OTHER, (16, 16))
titleIco = wx.StaticBitmap(self.panel, wx.ID_ANY, self.bmp1)
title = wx.StaticText(self.panel, wx.ID_ANY, 'mySQL Connect Test')
self.bmp2 = wx.ArtProvider.GetBitmap(wx.ART_TIP, wx.ART_OTHER, (16, 16))
inputOneIco = wx.StaticBitmap(self.panel, wx.ID_ANY, self.bmp2)
lblHost = wx.StaticText(self.panel, wx.ID_ANY, 'Hostname:')
self.txtHost = wx.TextCtrl(self.panel, wx.ID_ANY, 'localhost')
inputTwoIco = wx.StaticBitmap(self.panel, wx.ID_ANY, self.bmp1)
lblUSN = wx.StaticText(self.panel, wx.ID_ANY, 'Username')
self.txtUSN = wx.TextCtrl(self.panel, wx.ID_ANY, '')
inputThreeIco = wx.StaticBitmap(self.panel, wx.ID_ANY, self.bmp1)
lblPWD = wx.StaticText(self.panel, wx.ID_ANY, 'Password', style = wx.TE_PASSWORD)
self.txtPWD = wx.TextCtrl(self.panel, wx.ID_ANY, '', style = wx.TE_PASSWORD)
inputFourIco = wx.StaticBitmap(self.panel, wx.ID_ANY, self.bmp1)
lblSchema = wx.StaticText(self.panel, wx.ID_ANY, 'Default Schema:')
self.txtSchema = wx.TextCtrl(self.panel, wx.ID_ANY, '')
lblStatus = wx.StaticText(self.panel, wx.ID_ANY, 'Status:')
self.txtStatus = wx.TextCtrl(self.panel, wx.ID_ANY, 'Disconnected...')
self.okBtn = wx.Button(self.panel, wx.ID_ANY, 'OK')
self.cancelBtn = wx.Button(self.panel, wx.ID_ANY, 'Cancel')
self.btnConnect = wx.Button(self.panel, wx.ID_ANY, 'Connect')
self.btnDisconnect = wx.Button(self.panel, wx.ID_ANY, 'Disconnect')
self.Bind(wx.EVT_BUTTON, self.onOK, self.okBtn)
self.Bind(wx.EVT_BUTTON, self.onCancel, self.cancelBtn)
self.Bind(wx.EVT_BUTTON, self.onTryConnect, self.btnConnect)
self.list_ctrl = wx.ListCtrl(self.panel, size=(-1,100),
style=wx.LC_REPORT
|wx.BORDER_SUNKEN
)
self.list_ctrl.InsertColumn(0, 'Type')
self.list_ctrl.InsertColumn(1, 'Status')
self.list_ctrl.InsertColumn(2, 'Last')
self.list_ctrl.InsertColumn(3, 'Interval')
topSizer = wx.BoxSizer(wx.VERTICAL)
titleSizer = wx.BoxSizer(wx.HORIZONTAL)
gridSizer = wx.BoxSizer(wx.HORIZONTAL)
inputOneSizer = wx.BoxSizer(wx.HORIZONTAL)
inputTwoSizer = wx.BoxSizer(wx.HORIZONTAL)
inputThreeSizer = wx.BoxSizer(wx.HORIZONTAL)
nputFourSizer = wx.BoxSizer(wx.HORIZONTAL)
inputFourSizer = wx.BoxSizer(wx.HORIZONTAL)
inputFiveSizer = wx.BoxSizer(wx.HORIZONTAL)
btnSizer1 = wx.BoxSizer(wx.HORIZONTAL)
btnSizer2 = wx.BoxSizer(wx.HORIZONTAL)
titleSizer.Add(titleIco, 0, wx.ALL, 5)
titleSizer.Add(title, 0, wx.ALL, 5)
gridSizer.Add(self.list_ctrl, 0, wx.ALL, 5)
inputOneSizer.Add(inputOneIco, 0, wx.ALL, 5)
inputOneSizer.Add(lblHost, 0, wx.ALL, 5)
inputOneSizer.Add(self.txtHost, 1, wx.ALL | wx.EXPAND, 5)
inputTwoSizer.Add(inputTwoIco, 0, wx.ALL, 5)
inputTwoSizer.Add(lblUSN, 0, wx.ALL, 5)
inputTwoSizer.Add(self.txtUSN, 1, wx.ALL | wx.EXPAND, 5)
inputThreeSizer.Add(inputThreeIco, 0, wx.ALL, 5)
inputThreeSizer.Add(lblPWD, 0, wx.ALL, 5)
inputThreeSizer.Add(self.txtPWD, 1, wx.ALL | wx.EXPAND, 5)
inputFourSizer.Add(inputFourIco, 0, wx.ALL, 5)
inputFourSizer.Add(lblSchema, 0, wx.ALL, 5)
inputFourSizer.Add(self.txtSchema, 1, wx.ALL | wx.EXPAND, 5)
inputFiveSizer.Add(lblStatus, 0, wx.ALL, 5)
inputFiveSizer.Add(self.txtStatus, 0, wx.ALL, 5)
btnSizer1.Add(self.okBtn, 0, wx.ALL, 5)
btnSizer1.Add(self.cancelBtn, 0, wx.ALL, 5)
btnSizer2.Add(self.btnConnect, 0, wx.ALL, 5)
btnSizer2.Add(self.btnDisconnect, 0, wx.ALL, 5)
topSizer.Add(titleSizer, 0, wx.CENTER)
topSizer.Add(gridSizer, 0, wx.CENTER)
topSizer.Add(wx.StaticLine(self.panel, ), 0, wx.ALL | wx.EXPAND, 5)
topSizer.Add(inputOneSizer, 0, wx.ALL | wx.EXPAND, 5)
topSizer.Add(inputTwoSizer, 0, wx.ALL | wx.EXPAND, 5)
topSizer.Add(inputThreeSizer, 0, wx.ALL | wx.EXPAND, 5)
topSizer.Add(inputFourSizer, 0, wx.ALL | wx.EXPAND, 5)
topSizer.Add(inputFiveSizer, 0, wx.ALL | wx.EXPAND, 5)
topSizer.Add(wx.StaticLine(self.panel), 0, wx.ALL | wx.EXPAND, 5)
topSizer.Add(btnSizer1, 0, wx.ALL | wx.CENTER, 5)
topSizer.Add(btnSizer2, 0, wx.ALL | wx.CENTER, 5)
self.panel.SetSizer(topSizer)
topSizer.Fit(self)
self.list_ctrl.InsertItem(self.index, 0, "Optical")
self.list_ctrl.SetItem(self.index, 1, "Ready")
self.list_ctrl.SetItem(self.index, 2, "Start")
self.index += 1
def CheckConnection():
if self.cnx != None:
if cnx.is_connected(): print("\n Connected ? : YES")
self.txtStatus.SetValue("Connected")
else:
self.txtStatus.SetValue("Not Connected")
print("\n Connected ? : NO")
dictConnInfo = {'user': self.txtUSN.GetValue(),
'password': self.txtPWD.GetValue(),
'host': sel.txtHost.GetValue(),
'database': self.txtSchema.GetValue()
}
cnx = mysql.connector.connect( ** dictConnInfo)
if cnx.is_connected():
print("\n Connected ? : YES")
self.txtStatus.SetValue("Connected?: YES")
else:
print("\n Connected ? : NO")
self.txtStatus.SetValue("Connected?: NO")
if cnx.is_connected():
print("\n Connected ? : YES")
self.txtStatus.SetValue("Connected")
def onOK(self, event):
pass
def onTryConnect(self, event):
self.txtStatus.SetValue("Connected?: NO")
dictConnInfo = {'user': self.txtUSN.GetValue(),
'password': self.txtPWD.GetValue(),
'host': self.txtHost.GetValue(),
'database': self.txtSchema.GetValue()
}
cnx = mysql.connector.connect( ** dictConnInfo)
if cnx.is_connected():
print("\n Connected ? : YES")
self.txtStatus.SetValue("Connected?: YES")
else:
print("\n Connected ? : NO")
self.txtStatus.SetValue("Connected?: NO")
if cnx.is_connected():
print("\n Connected ? : YES")
self.txtStatus.SetValue("Connected?: YES")
def onCancel(self, event):
self.Close()
def closeProgram(self, event):
self.Close()
if __name__ == '__main__':
app = wx.App()
frame = MyForm().Show()
app.MainLoop()