我使用Sublime Text 3,打印西里尔字符就可以了。但是,当将相同的字符串插入到Tkinter列表框中时,该字符串保持不变。字符串为:
st = '\u0418\u0441\u0442\u043e\u0440\u0438\u044f \u0414\u0440\u0435\u0432\u043d\u0435\u0438\u0306 \u0413\u0440\u0435\u0446\u0438\u0438 \u0421\u0435\u0440\u0433\u0435\u044f \u041a\u0430\u0440\u043f\u044e\u043a\u0430.mp4'
print(st)
История Древней Греции Сергея Карпюка.mp4我已经尝试过这个构建系统:
{
"shell_cmd": "python \"$file\"",
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python",
"env": {"PYTHONIOENCODING": "utf8"}
}发布于 2021-05-12 20:57:56
通过运行下面的代码,我能够将字符串插入到标签和列表框中,没有任何问题。
import tkinter as tk
st = '\u0418\u0441\u0442\u043e\u0440\u0438\u044f \u0414\u0440\u0435\u0432\u043d\u0435\u0438\u0306 \u0413\u0440\u0435\u0446\u0438\u0438 \u0421\u0435\u0440\u0433\u0435\u044f \u041a\u0430\u0440\u043f\u044e\u043a\u0430.mp4'
print(st)
root = tk.Tk()
label = tk.Label(root, text=st)
label.pack()
listbox = tk.Listbox(root)
listbox.insert(0, st)
listbox.pack(fill=tk.X, expand=True)
root.mainloop()

发布于 2021-05-13 01:35:24
对我来说,有效的解决方案是在通常模式下使用文件读取,而不是在open( file )命令中指定编码。因为日志包含几种语言的文件名,所以我不得不使用2次尝试,除了块。
with open(LOG, 'r') as f:
for line in f:
for part in line:
try:
# this fixes Cyrillic file names
part = part.encode('utf8').decode("unicode_escape")
except Exception as e:
print(e)
try:
# this fixes French, German file names
part = part.encode('latin1').decode('utf8')
except Exception as e:
print(e)
listboxMain.insert(tk.END,part)https://stackoverflow.com/questions/67503896
复制相似问题