I'm trying to write an interface (in Python 3.8, using tkinter) to accept text in Greek (typed using the Greek Polytonic keyboard in Windows 10). However, the Entry and Text won't accept all typed Greek characters: Greek letters by themselves can be typed, but if I try to type any letters with diacritics other than the acute accent, ? is displayed instead of the character. (I think that tkinter accepts characters in the "Greek and Coptic" but not the "Greek Extended" Unicode block.) I know that tkinter can display such characters because they show up fine when they're inserted by the program (e.g. TextInstance.insert(tkinter.INSERT, 'ῆ') inserts ῆ but just typing that character using the keyboard's shortcut inserts ?). What do I need to do for tkinter to recognize typed Greek characters?(I also tried just re-binding the keyboard shortcuts by adding TextInstance.bind('[h', lambda *ignored: TextInstance.insert(tkinter.INSERT, 'ῆ'))with each character and its shortcut; that worked in the English keyboard (although the characters that activated the event were also inserted), but in the Greek Polytonic keyboard bindings on letter keys weren't activated at all.)推荐答案γειασουφιλε,γεια σου φιλε, unicode与tkinter和python完美配合unicode works perfectly fine with tkinter and python您可能还会对Unicode 希腊语 + 扩展"You may are also intrested in the unicode "greek + extended"我的第一个答案太短,无法给出该技术背后的全部思想:因此,想法是在需要时转换字符.My first answer was too short to give the whole idea behind this technic:So the idea is that you transform the characters when needed.我记得在希腊键盘上,您按住alt并按下要转换的字符,如果多次按下,它将再次更改.As I remember right on the greek keyboard you press and hold alt and press a character that you want to transform, if pressed multiple times it changes again.这就是我要做的,使其更明确,希望它能给您带来使您的代码按您喜欢的方式工作的想法.Here is what I've made to make it more explicit and hope it will give you the idea to make your your code work how you like it.import tkinter as tkroot = tk.Tk()E = tk.Entry(root)E.pack()_mod = tk.BooleanVar(value=False)_val = tk.StringVar()def tracker(event): if event.keysym_num == 65513: _mod.set(True) #check if "left alt" key was pressed and set flag key = event.keysym #check which key was preesed if _mod.get() and event.char != '': #if flag(_mod is True and character is char if key == 'a': #if key is char a if not _val.get(): #if there wasn't an setting yet for _val a = '\u03B1' #unicode alpha if _val.get() == '\u03B1': #if _val.get is unicode alpha a = '\u03AC' #unicode alpha with tonos _val.set(a) return "break" #dont go for default bindingdef mod_off(event): _mod.set(False) #set flag to false val = _val.get() #get the chosen character E.insert('end', val) #insert it in entry _val.set('') #set _val to nothingE.bind('<Key>',tracker)E.bind('<KeyRelease-Alt_L>', mod_off)root.mainloop() 这篇关于在Tkinter中键入希腊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-11 18:35