Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

النص مقلوب من الأسفل إلى الأعلى #16

Open
youssefhoummad opened this issue Jan 8, 2023 · 1 comment
Open

Comments

@youssefhoummad
Copy link

youssefhoummad commented Jan 8, 2023

image

السلام عليكم


    root = tk.Tk()
    txt = 'السلام عليكم'

    # text display incorrectly on linux
    dummyvar = tk.StringVar()
    dummyvar.set(txt)
    tk.Label(root, textvariable=dummyvar, font='any 20').pack()

    # uncomment below to set a rendered text to first label
    dummyvar.set(render_bidi_text(txt))

    entry = tk.Entry(root, font='any 20', justify='right')
    entry.pack()

    lbl = tk.Label(root, font='any 20', wraplength=300)
    lbl.pack()

    # adding bidi support for widgets
    add_bidi_support(lbl)
    add_bidi_support(entry)

    # we can use set() and get() methods to set and get text on a widget
    entry.set(txt)
    lbl.set('لغتنا الجميلة، كان هذا عنوان إحدى البرامج الإذاعية و الذي كنا ننتظره و نتعلم كيفية نطق لغتنا العربية الأصيلة بكل ما فيها من كلمات و معاني')

    root.mainloop()

الكلام مقلوب من الأسفل للأعلى عند استخدام render_text مع wraplength في label

@Aboghazala
Copy link
Owner

Aboghazala commented Jan 9, 2023

وعليكم السلام
للاسف (tkinter) لا يتعامل بحرفية مع اللغة العربية او مع اى لغة تكتب من اليمين لليسار لذلك تجد النص معكوس كما فى المثال الذى عرضته
لذلك يجب عمل معالجة كاملة للنص قبل عرضه فى الواجهة الرسومية
لحل هذه المشكلة يمكن الاستعانة بمكتبة بايثون textwrap
الكود المعدل كالتالى:

import tkinter as tk
import awesometkinter as atk
from awesometkinter.bidirender import render_bidi_text, add_bidi_support
from textwrap import wrap

root = tk.Tk()
txt = 'السلام عليكم'

# text display incorrectly on linux
dummyvar = tk.StringVar()
dummyvar.set(txt)
tk.Label(root, textvariable=dummyvar, font='any 20').pack()

# uncomment below to set a rendered text to first label
dummyvar.set(render_bidi_text(txt))

entry = tk.Entry(root, font='any 20', justify='right')
entry.pack()

lbl = tk.Label(root, font='"Droid Arabic Kufi" 20')  # don't use tkinter "wraplength" here
lbl.pack()

# adding bidi support for widgets
add_bidi_support(lbl)
add_bidi_support(entry)

# we can use set() and get() methods to set and get text on a widget
entry.set(txt)

txt =  'لغتنا الجميلة, كان هذا عنوان إحدى البرامج الإذاعية و الذي كنا ننتظره و نتعلم كيفية نطق لغتنا العربية الأصيلة بكل ما فيها من كلمات و معاني'
txt = '\n'.join(wrap(txt, 40))  # wrap text with 40 character width
lbl.set(txt)
root.mainloop()

بعد التعديل

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants