I have create in MySQdb a DB with a table named example,in this table i want to save a name, this name is in Greek language.My problem is thw follown when i try to save the name instantly without use textctrl, its ok but when i use textctrl i take error.Look the code: Can anyone hel me please i have try encoding in utf-8,decoding in utf-8, to unicode but nothing.
import os
import math
import random
import wx
import MySQLdb
import sys
APP_SIZE_X = 500
APP_SIZE_Y = 300
# -*- coding: utf-8 -*-
class MyFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, size=(APP_SIZE_X, APP_SIZE_Y))
panel = wx.Panel(self, -1,style=wx.SUNKEN_BORDER)
wx.StaticText(panel, -1,'Name', (10, 55),style=wx.LEFT)
self.name = wx.TextCtrl(panel, -1, '', (110, 55), (120, -1))
save = wx.Button(panel, 1, 'Save', (70, 215),(130,-1))
save.Bind(wx.EVT_BUTTON,self.OnSaveAsFile)
quitbtn = wx.Button(panel, 1, 'Quit', (250, 215),(130,-1))
quitbtn.Bind(wx.EVT_BUTTON,self.OnQuit)
def OnSaveAsFile(self, event):
idis="000"
newname=self.name.GetValue()
db=MySQLdb.connect(host="localhost",use_unicode="True",charset="utf8",user="root",passwd="root",db="test")
cursor=db.cursor()
sql="""INSERT INTO example(name) VALUES("%s","%s")"""%(idis,newname)
try:
cursor.execute(sql)
db.commit()
print 'save ok'
except:
print 'no save'
db.rollback()
def OnQuit(self,e):
self.Close()
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, 'form1.py')
frame.Show(True)
self.SetTopWindow(frame)
return True
app = MyApp(0)
app.MainLoop()