이 테이블에 예제라는 이름의 테이블이있는 MySQdb를 작성했습니다.이 이름은 그리스어로되어 있습니다. 이 이름은 그리스어로되어 있습니다. 내 문제는 다음과 같습니다. 사용하지 않고 즉시 이름을 저장합니다. textctrl을 사용할 때 textctrl을 사용할 때 error.Look 코드를 봅니다. 누구든지 제게 utf-8로 인코딩하려고 시도 할 수 있습니까? utf-8로 인코딩하면 유니 코드 만 읽을 수 있습니다.Greek 문자는 TextCtrl을 통해 mysqldb를 삽입합니다. ERROR
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을 사용합니다. – TLSK
아니요. 위조 할 수 없습니다. – TLSK
그런 다음 wxPython 메일 링리스트에서 질문 해보십시오. 이런 것들을하는 법을 아는 사람들이 여러 명 있습니다. –