user2056847
user2056847

Reputation: 3

Gtk gives a warning and won't show my menu item

The python code: menu_item = gtk.MenuItem("après") gives a warning message: Gtk warning Invalid input string and the menu item is not shown. What should I add / change to have the menu item displayed?

Upvotes: 0

Views: 601

Answers (1)

user4815162342
user4815162342

Reputation: 154886

Your editor is most likely saving the source file in another encoding, such as Latin-1 or Windows-1252, where GTK expects UTF-8. Try replacing "après" with u"apr\u00e8s".encode("utf-8"). If that makes it work, the problem lies there.

To correctly fix the problem, you need to:

  • declare the encoding to Python using the # -*- coding: utf-8 -*-
  • make sure your editor is saving the file in the declared encoding. If necessary, use a hex editor to verify this.
  • use Unicode string literals for non-ASCII strings, i.e. u"après" instead of "après". Where unicode strings are not accepted, use u"après".encode("utf-8"). PyGTK generally accepts Unicode strings, so explicit encoding to UTF-8 should not be necessary.

Upvotes: 1

Related Questions