问题
I'm working on a python GUI application, using tkinter, which displays text in Hebrew.
On Windows (10, python 3.6, tkinter 8.6) Hebrew strings are displayed fine.
On Linux (Ubuntu 14, both python 3.4 and 3.6, tkinter 8.6) Hebrew strings are displayed incorrectly - with no BiDi awareness - am I missing something?
I installed pybidi, and via bidi.algorithm.get_display(hebrew_string)
- the strings are displayed correctly.
But then, on Windows, get_display(hebrew_string)
is displayed incorrectly.
Is BiDi not supported on python-tkinter-Linux?
Must I wrap each string with get_display(string)
?
Must I wrap get_display(string)
with a only_on_linux(...)
function?
回答1:
I searched a bit and it is a known issue that tk/tcl uses Windows bidi support since about 2011, but their is apparently nothing equivalent on linux. Example: https://wiki.tcl.tk/3158. One answer to Python/Tkinter: Using Tkinter for RTL (right-to-left) languages like Arabic/Hebrew? has some workarounds for *nix. I am not sure about Mac support with the latest tcl/tk.
For cross-platform work you will need a function that echoes on Windows and reverses on your Ubuntu.
回答2:
As on of the main authors of FriBidi and a contributor to the bidi text support in Gtk, I strongly suggest that you don't use TkInter for anything Hebrew or any other text other than Latin, Greek, or Cyrillic scripts. In theory you can rearrange the text ordering with the stand alone fribidi executable on on Linux, or use the fribidi binding, but bidi and complex language support goes well beyond that. You might need to support text inserting, cut and paste, shaping, just to mention a few of the pitfalls. You are much better off using the excellent gtk or Qt bindings to python.
来源:https://stackoverflow.com/questions/47249474/hebrew-with-tkinter-bidi