我想将 •
插入 GtkTextView 小部件。在 Python + pyGTK 中,这一行就足够了:
self.__textBuffer.insert_at_cursor(u'\u2022')
因为我正在将我的应用程序重写为 C,所以我需要翻译这行代码。
我试图做:
gtk_text_buffer_insert_at_cursor(textBuffer, "\x20\x22", 2);
但是没用,只插入了2个字符"*
。
如何将 u'\u2022' 从 Python 翻译为 C?
最佳答案
你需要对其进行UTF-8编码,因为GTK+的编码是UTF-8。
因此:
const char bullet_utf8[] = "\xe2\x80\xa2";
gtk_text_buffer_insert_at_cursor(textBuffer, bullet_utf8, strlen(bullet_utf8));
可以看到这个字符的UTF-8编码here, for instance .
关于python - 如何在 GtkTextView 中插入 UTF8 文字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10188807/