我在MySQdb中創建了一個名爲example的數據庫,在這個表中我想保存一個名字, 這個名字是希臘語language.My問題是thw follown,當我嘗試保存名稱即時沒有使用textctrl,它的好,但是當我使用textctrl我犯錯誤。查看代碼: 任何人都可以幫助我,請嘗試在utf-8編碼,在utf-8解碼,unicode,但沒有。希臘字符通過TextCtrl插入mysqldb錯誤
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 TB_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()
是的,我使用wxpython的unicode版本 – TLSK 2012-02-22 18:41:53
不,我不能僞造它 – TLSK 2012-02-22 18:51:10
然後嘗試詢問wxPython郵件列表。那裏有幾個人知道如何做這樣的事情。 – 2012-02-22 19:23:37