est-il possible d'utiliser Tkinter pour rendre les interfaces utilisateur pour les langages RTL tels que l'arabe ou l'hébreu? J'ai essayé Googling sur "Tkinter RTL" et les résultats de la recherche étaient décevants. Le tk wiki indique qu'il n'y a pas de support de bidi pour le moment. P>
Est-ce que quelqu'un développe des applications Tkinter pour les locaux arabes ou hébreux? p>
3 Réponses :
Je réalise que c'est une vieille question, mais je viens de commencer à travailler avec Tkinter hier pour développer une application hébraïque à Python. Le droit à gauche (BIDI) n'est pas disponible dans le cadre du cadre, mais après un peu de googling et de certaines recherches, j'ai réussi à simuler de manière convaincante la simulacre à travers des clés et repositionnez de force le curseur. Mon widget de saisie maintient la justification à gauche, de sorte que le texte hébraïque soit à peu près la même position que certains anglais sur la même boîte, mais cette approche pourrait être facilement modifiée pour une boîte justifiée à droite. (Ou une justification de droite pourrait rendre cela plus simple). Néanmoins, voici ce que j'ai fait.
Essentiellement ce que vous faites ici appliquer manuellement la position du curseur à l'aide de rappels, de codes de caractères et de constantes d'index. De plus, vous devez rendre compte des touches fléchées (le mien se comporte comme bouger dans la direction qu'ils pointillent. J'ai toujours détesté comment RTL inverse généralement les flèches. Cela est facilement modifié, si vous préférez sinon.) Retour arrière et del, De plus, doivent causer un peu de repositionnement manuel. Bien sûr, si vous gardez une trace du curseur manuellement, vous devez mettre à jour votre variable de suivi dans le cas où l'utilisateur repositionnez-le à l'aide de la souris. Vous trouverez ci-dessous mon code, à l'exception de l'utilisation d'un global ici destiné à éliminer un acarien de complexité de l'explication. P> Suivant, les trois fonctions de rappel, qui Faites tout notre curseur de suivi et de relocalisation. P> #With the following functions, keep in mind that we only want the cursor to move RIGHT
#(increase in index) in response to a right arrow press or a DEL. Essentially, we are
#compensating for any movement but these explicit conditions. Since the indexing of the
#cursor position is LTR, holding it in its current position
#while we append more text is
#tantamount to moving it right.
#On key release, if an arrow key has been invoked, we update our tracking variable to
#reflect the new cursor position. If any other key was pressed, we snap the cursor back
#to where it was prior to the keypress to prevent it from moving right and cause the
#next letter to be appended on the left side of the previous letter.
def rtlRelease(event):
global hebCursorPos
if event.keycode==114 or event.keycode==113:
hebCursorPos=event.widget.index(INSERT)
else:
event.widget.icursor(hebCursorPos)
print(str(event.keycode)+" "+str(hebCursorPos))
#On keypress, we must compensate for the natural LTR behavior of backspace(22) and
#del(119)
def rtlPress(event):
global hebCursorPos
#In LTR text entry, a backspace naturally removes the character to the left of
#the cursor.
if event.keycode==22:
length = len(event.widget.get())
#In RTL, the right edge is the beginning of the string, so backspace
#should do nothing.
#If we're at the right edge of the string, we insert a meaningless
#character to be deleted so that it appears to the user as if we have
#done nothing.
if hebCursorPos==length:
event.widget.insert(hebCursorPos, " ")
#In order to cause the backspace to delete the character to the right
#rather than the left of the cursor from the user's perspective, we step
#the cursor forward one. This will cause the backspace to delete the
#character to the left of the new cursor position, which will be the
#character that was to the right of the cursor from the user's
#perspective. If we were at the right end of the line, we insert a space
#and delete it milliseconds later. We do not need to update the cursor's
#position, in the tracking variable, because after the character is
#deleted, it is back at the index from which it started, counting index
#from an LTR perspective.
event.widget.icursor(hebCursorPos+1)
else:
#Del is more of the same. It deletes the character to the right of the
#cursor, but we want it to delete the character to the right.
if event.keycode==119:
#If we're at the left edge of the string, insert a meaningless character
#for the del to delete, so that from the user's perspective it does
#nothing.
if hebCursorPos==0:
event.widget.insert(hebCursorPos, " ")
#Otherwise, we will be stepping the cursor one to the left, so
#that when it deletes the character to its new right, it will be
#deleting the character from what the user thinks is its left.
#Because we are deleting a character from the left of the cursor
#from the user's perspective, there will be fewer characters to
#the left of the cursor once the operation is complete. As
#cursor positioning is tracked as an LTR index, we must update
#our tracking variable.
else:
hebCursorPos-=1
#Now, we snap our cursor to the position of our tracking variable.
#Either we are preventing it from drifting right due to overlapping
#keypresses, or we are repositioning it to maintain the correct index
#after a del.
event.widget.icursor(hebCursorPos)
#Simply put, if the user repositions the cursor with the mouse, track it.
def rtlMouse(event):
global hebCursorPos
hebCursorPos=event.widget.index(INSERT)
C'est un hall horrible et ne s'attaque à une fraction des problèmes présentés par le rendu de texte arabe / hébreu.
Cela ne résout peut-être pas non plus tout le problème, mais cela peut résoudre le problème de l'affichage que je vois le problème principal. P>
En gros, vous aurez besoin de deux choses pour inverser l'ordre de caractère et de les laisser rejoindre ensemble
J'ai utilisé ce Reshaire , cela a fonctionné bien avec des mots simples sans diagritique الحركات code> mais il est toujours buggy dans certains cas. P>
Essayez de définir l'entrée ou un autre élément sur "Jameel NOORI NASTALEEQ" ou toute autre police URDU P>
Un peu plus à ce sujet à: wiki.tcl.tk/699
Depuis environ 2011, TK et donc le support TKINTER et IDLE BIDI Hébreu et l'arabe sur Windows utilisent la prise en charge de Windows. wiki.tcl.tk/3158 . Je viens d'ajouter une partie de chacun de chacun à l'échantillon de sélection de polices sur oisif afin que les gens puissent voir ce qui fonctionne ou non sur leur système particulier.