fbence
fbence

Reputation: 2153

unicode window title on windows

I thought that in the 21st century this is not a problem, but:

import sys
from PySide import QtGui
print('\u2122')
app = QtGui.QApplication(sys.argv)
widget = QtGui.QWidget()
widget.setWindowTitle('\u2122')
widget.show()
sys.exit(app.exec_())

on Ubuntu displays the trademark symbol in both the window and the terminal, on Windows (10) it displays \u2122 both places. I am using python 3.4 on both systems, on windows it's an Canopy install, if that helps anything, but probably totally unrelated to that. How can I get unicode characters to display on Windows as well?

EDIT

Okay, so it turned out that having print() doesn't make it python 3, my bad. Although the Windows python 2.7.9 gives an interesting error when I fix the strings to u'\u2122:

File "C:\Program Files\Enthought\Canopy32\App\appdata\canopy-1.5.5.3123.win-x86\lib\encodings\cp852.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u2122' in position 0: character maps to <undefined>

Anyway, installing a 3.x will solve the issue.

Upvotes: 0

Views: 434

Answers (1)

Alastair McCormack
Alastair McCormack

Reputation: 27744

Ensure that you have Python 3.x on your Windows box. The results are consistent with using Python 2.x.

To make your code with 2.x, change the strings into Unicode strings by appending a u to each one. E.g.

widget.setWindowTitle('\u2122')

On Windows, don't try to print Unicode to the console - it's totally broken. If you must, see the following module which allows it: https://github.com/Drekin/win-unicode-console

Upvotes: 1

Related Questions