答案 0 :(得分:1)
由于阿拉伯语脚本从右到左,您可以使用这些库:https://github.com/mpcabd/python-arabic-reshaper和https://github.com/MeirKriheli/python-bidi
这样的事情可以起作用:
# !/usr/bin/python3
from tkinter import *
import arabic_reshaper
from tkinter import messagebox
from bidi.algorithm import get_display
text_to_be_reshaped = "ﺏﺎﻃﻭ"
reshaped_text = arabic_reshaper.reshape(text_to_be_reshaped)
bidi_text = get_display(reshaped_text)
top = Tk()
top.geometry("70x30")
B = Button(top, text = bidi_text)
B.place(x=0,y=0)
top.mainloop()
答案 1 :(得分:1)
希望这个答案可以帮助某人
这是如何向 tkinter 标签和条目小部件添加阿拉伯语支持
编辑: 此修复程序仅适用于 linux 上的阿拉伯语, 但对于 Windows,bidi 支持将由操作系统处理,阿拉伯语将正确显示,无需修复。
您需要安装 AwesomeTkinter 包 pip install awesometkinter
示例 (source):
import tkinter as tk
from awesometkinter.bidirender import add_bidi_support, render_text
root = tk.Tk()
text = 'السلام عليكم'
# text display incorrectly on linux without bidi support
dummyvar = tk.StringVar()
dummyvar.set(text)
tk.Label(root, textvariable=dummyvar, font='any 20').pack()
# uncomment below to set a rendered text to first label
# dummyvar.set(render_text(text))
entry = tk.Entry(root, font='any 20', justify='right')
entry.pack()
lbl = tk.Label(root, font='any 20')
lbl.pack()
# adding bidi support for widgets
add_bidi_support(lbl)
add_bidi_support(entry)
# now there is a new set() and get() methods to set and get text on a widget
entry.set(text)
lbl.set('هذا كتاب adventure شيق')
root.mainloop()
输出:
注意:正常情况下可以直接在输入小部件中书写阿拉伯语,文本从右到左正确流向,字母正确连接