Skip to main content
 首页 » 编程设计

python之带有阿拉伯文字的 Tkinter 标签

2025年02月15日13EasonJim

有什么方法可以使阿拉伯语文本看起来完全像它必须的那样: 下面的例子应该看起来像“باطو”

请您参考如下方法:

由于阿拉伯文字是从右到左,您可以使用库: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()