WxPython window Chinese garbled code solution

  • 2020-04-02 14:14:17
  • OfStack

This article illustrates the wxPython window Chinese garbled code solution, to share for your reference. Specific methods are as follows:

Save the file as utf-8
Add # -*- coding: utf-8 -*- at the beginning of the file
Add u or u before Chinese string, for example :u "my website ://www.jb51.net"

Here's an example:

# -*- coding: utf-8 -*-
import wx
class App(wx.App):
 
    def OnInit(self):
        frame = wx.Frame(parent=None, title=u' My website ://www.jb51.net')
        frame.Show()
        return True
 
app = App()
app.MainLoop()

Unicode string:

Unicode is the standard method for writing international text. If you want to write text in your native language such as Hindi or Arabic, you need a unicode-enabled editor. Similarly, Python allows you to work with Unicode text -- you just prefix strings with u or u. For example, u "This is a Unicode string."

Also remember to use Unicode strings when working with text files, especially if you know that the file contains text written in a non-english language.

I hope this article has helped you with your Python programming.


Related articles: