1 #coding:utf-8 2 import wx 3 4 def load(event): 5 f = open(FileName.GetValue()) 6 Contents.SetValue(f.read().decode(\'utf-8\')) 7 f.close() 8 9 def save(event): 10 f = open(FileName.GetValue(), \'w\') 11 f.write(Contents.GetValue()) 12 f.close() 13 14 app = wx.App() 15 win = wx.Frame(None, title = "Simple Editor", size = (410, 335)) 16 bkg = wx.Panel(win) 17 18 LoadButton = wx.Button(bkg, label = "Open") 19 LoadButton.Bind(wx.EVT_BUTTON, load) 20 SaveButton = wx.Button(bkg, label = "Save") 21 SaveButton.Bind(wx.EVT_BUTTON, save) 22 FileName = wx.TextCtrl(bkg) 23 Contents = wx.TextCtrl(bkg, style = wx.TE_MULTILINE | wx.HSCROLL) 24 25 hbox = wx.BoxSizer() 26 hbox.Add(FileName, proportion = 1, flag = wx.EXPAND) 27 hbox.Add(LoadButton, proportion = 0, flag = wx.LEFT, border = 5) 28 hbox.Add(SaveButton, proportion = 0, flag = wx.LEFT, border = 5) 29 30 vbox = wx.BoxSizer(wx.VERTICAL) 31 vbox.Add(hbox, proportion = 0, flag = wx.EXPAND | wx.ALL, border = 5) 32 vbox.Add(Contents, proportion = 1, flag = wx.EXPAND | wx.LEFT | wx.BOTTOM | wx.RIGHT, 33 border = 5) 34 35 bkg.SetSizer(vbox) 36 win.Show() 37 38 app.MainLoop()
Python输出中文到文件时的字符编码问题
内容版权声明:除非注明,否则皆为本站原创文章。