python - 如何在 GtkTextView 中插入 UTF8 文字?

标签 python c utf-8 gtk

我想将 插入 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/

相关文章:

python - 使用生成器进行列表理解

c - 在 C 程序中使用汇编函数

c - 使用 fread 和 fwrite .. 数据丢失

utf-8 - GLIB UTF16BE 和 UTF-16BE 之间的区别以及如何支持 UTF16BE

Python 3 正则表达式问题

python - 排序 WTForms form.errors dict

python - 无法使用 Python Selenium 找到shadow-root(打开)中的元素

c++ - 在 C 和 C++ 中捕获 SIGBUS

html - 如何将中文文本粘贴到没有 UTF-8 元标记的 html 片段中?

c# - 为什么我在执行 HTTP POST 时用完了流的字节数?