从右向左更改文本方向

时间:2018-11-02 13:05:21

标签: windows tkinter python-3.7 text-widget

我正在使用Tkinter, 我正在尝试更改希伯来语和阿拉伯语等语言的文本小部件方向(当用户输入时,它将是RTL)。

如何允许 declare @test table ( ID bigint identity(1,1), GlobalFamilyUniqueID int, DupeIdentifier as cast('EDME' + RIGHT('00000000'+ISNULL(cast([ID] as nvarchar(max)),''),8) as nvarchar(30)), ControlNumber nvarchar(30), MD5Hash nvarchar(32), IsGlobalFamilyUnique bit ) insert into @test (MD5Hash, IsGlobalFamilyUnique)values --1 ('ABC', 1), --2 ('DEF', 1), --3 ('GHI', 1), --4 ('JKL', 1), --5 ('ABC', 0), --6 ('XXX', 1) 以便文本方向会改变rtl和ltr?

还是有另一种方法?

1 个答案:

答案 0 :(得分:0)

我有一个正在进行的工作示例。

在这里,我基于列表创建2个标签。然后,我们可以使用翻转文本的方法来更改文本的格式。我觉得它应该切换回LTR并锚定回左侧,但该部分由于某种原因无法正常工作。我会继续努力,但是如果有人知道为什么,那就让我知道。

import tkinter as tk


class Example(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self.columnconfigure(0, weight=1)
        self.testing_frame = tk.Frame(self)
        self.testing_frame.grid(row=0, column=0, stick="nsew")
        self.testing_frame.columnconfigure(0, weight=1)

        self.list_of_items = ["Word to be reversed!", "Some other words to be reversed!"]
        self.list_of_labels = []
        for ndex, item in enumerate(self.list_of_items):
            self.list_of_labels.append([tk.Label(self.testing_frame, text=item, anchor="w"), "ltr"])
            self.list_of_labels[ndex][0].grid(row=ndex, column=0, sticky="ew")

        self.bind("<Control-Shift_L>", self.flip)

    def flip(self, event):
        for item in self.list_of_labels:
            if item[1] == "ltr":
                item[0].config(text=item[0]["text"][::-1], anchor="e")
                item[0].grid(sticky="ew")
                item[1] = "rtl"
            else:
                item[0].config(text=item[0]["text"][::-1], anchor="w")
                item[0].grid(sticky="ew")
                item[1] = "ltr"


if __name__ == "__main__":
    Example().mainloop()

结果:

enter image description here

enter image description here

现在有重量!

enter image description here

enter image description here