Hello!
I have written this dialog to connect to a MySQL database. It asks for the Username and Password, and it should use this data to connect to the database.
#! /usr/bin/env python
# pwd.py
import wx, MySQLdb
class LoginDlg(wx.Dialog):
def __init__(self):
wx.Dialog.__init__(self, None, -1, 'Login', size=(250,150))
# widgets
userLbl = wx.StaticText(self, wx.ID_ANY, 'Username:', size=(75, -1))
self.userTxt = wx.TextCtrl(self, wx.ID_ANY, '', size=(200, -1))
passwordLbl = wx.StaticText(self, wx.ID_ANY, 'Password:', size=(75, -1))
self.passwordTxt = wx.TextCtrl(self, wx.ID_ANY, '',style=wx.TE_PROCESS_ENTER|wx.TE_PASSWORD, size=(200, -1))
loginBtn = wx.Button(self, wx.ID_YES, 'Login')
cancelBtn = wx.Button(self, wx.ID_ANY, 'Cancel')
# sizer / layout
userSizer = wx.BoxSizer(wx.HORIZONTAL)
passwordSizer = wx.BoxSizer(wx.HORIZONTAL)
btnSizer = wx.BoxSizer(wx.HORIZONTAL)
mainSizer = wx.BoxSizer(wx.VERTICAL)
userSizer.Add(userLbl, 0, wx.ALL, 5)
userSizer.Add(self.userTxt, 0, wx.ALL, 5)
passwordSizer.Add(passwordLbl, 0, wx.LEFT|wx.RIGHT, 5)
passwordSizer.Add(self.passwordTxt, 0, wx.LEFT, 5)
btnSizer.Add(loginBtn, 0, wx.ALL, 5)
btnSizer.Add(cancelBtn, 0, wx.ALL, 5)
mainSizer.Add(userSizer, 0, wx.ALL, 0)
mainSizer.Add(passwordSizer, 0, wx.ALL, 0)
mainSizer.Add(btnSizer, 0, wx.ALL, 5)
# Logged in variable
self.loggedIn = False
self.SetSizer(mainSizer)
self.Fit()
self.Layout()
Username = self.userTxt.GetValue()
pwd = self.passwordTxt.GetValue()
db= MySQLdb.connect(host='localhost', user=Username , passwd=pwd, db='Ornithobase')
app = wx.App()
Login = LoginDlg()
result = Login.ShowModal()
Login.Destroy()
However, when I run the code I get this traceback
Traceback (most recent call last):
File "pwd.py", line 45, in <module>
Login = LoginDlg()
File "pwd.py", line 42, in __init__
db= MySQLdb.connect(host='localhost', user=Username , passwd=pwd, db='Ornithobase')
File "/usr/lib/pymodules/python2.6/MySQLdb/__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 170, in __init__
super(Connection, self).__init__(*args, **kwargs2)
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'acrocephalus'@'localhost' (using password: NO)")
Can anyone help?
Cheers!
Dani