[Tutor] putting accent on letters while user is typing in Entrybox (Tkinter)

Ali M adeadmarshal at gmail.com
Mon Jul 16 13:29:55 EDT 2018

The accents which i want to be automatically converted and put upon letters
is circumflex and another one which shape is like the opposite of

the user types in entrybox and it searches in db which i've created before
and has no problem. the words in my db have unicode characters and they are
accented. the user himself can type accented characters too, but i want to
make it automatically converted so the user doesn't have to have a special
keyboard to write.

when x is pressed after these letters (g,j,c,h,u), i want that x to be
removed and replaced with a circumflex above those letters.

here is the full code if needed:

import sqlite3 as sqlite
import tkinter as tk
from tkinter import ttk
#GUI Widgets

class EsperantoDict:
    def __init__(self, master):

        master.resizable(False, False)
        self.style = ttk.Style()
        self.search_var = tk.StringVar()
        self.search_var.trace("w", lambda name, index, mode:

        self.style = ttk.Style()
        self.style.configure("TFrame", background='#EAFFCD')
        self.style.configure("TButton", background='#C6FF02')
        self.style.configure("TLabel", background='#EAFFCD')

        self.frame_header = ttk.Frame(master, relief=tk.FLAT)
        self.frame_header.pack(side=tk.TOP, padx=5, pady=5)

        self.logo = tk.PhotoImage(file=r'C:\EsperantoDict\eo.png')
        self.small_logo = self.logo.subsample(10, 10)

        ttk.Label(self.frame_header, image=self.small_logo).grid(row=0,
column=0, stick="ne", padx=5, pady=5, rowspan=2)
        ttk.Label(self.frame_header, text='EsperantoDict', font=('Arial',
18, 'bold')).grid(row=0, column=1)

        self.frame_content = ttk.Frame(master)

        self.entry_search = ttk.Entry(self.frame_content,
textvariable=self.search_var, width=30)
        self.entry_search.bind('<FocusIn>', self.entry_delete)
        self.entry_search.bind('<FocusOut>', self.entry_insert)
        self.entry_search.grid(row=0, column=0, padx=5)

        self.button_search = ttk.Button(self.frame_content, text="Search")
        self.photo_search =
        self.small_photo_search = self.photo_search.subsample(3, 3)
compound=tk.LEFT, style="TButton")
        self.button_search.grid(row=0, column=2, columnspan=1, sticky='nw',

        self.listbox = tk.Listbox(self.frame_content, height=30, width=30)
        self.listbox.grid(row=1, column=0, padx=5)
        self.scrollbar = ttk.Scrollbar(self.frame_content,
orient=tk.VERTICAL, command=self.listbox.yview)
        self.scrollbar.grid(row=1, column=1, sticky='nsw')
        self.listbox.bind('<<ListboxSelect>>', self.enter_meaning)

        self.textbox = tk.Text(self.frame_content, relief=tk.GROOVE,
width=60, height=30, borderwidth=2)
        self.textbox.grid(row=1, column=2, sticky='w', padx=5)

        # SQLite
        self.db = sqlite.connect(r'C:\EsperantoDict\test.db')
        self.cur = self.db.cursor()
        self.cur.execute('SELECT Esperanto FROM Words')
        for row in self.cur:
            self.listbox.insert(tk.END, row)
        for row in range(0, self.listbox.size(), 2):
            self.listbox.itemconfigure(row, background="#f0f0ff")

    def update_list(self):
        search_term = self.search_var.get()
        for item in self.listbox.get(0, tk.END):
            if search_term.lower() in item:
                self.listbox.delete(0, tk.END)
                self.listbox.insert(tk.END, item)

    # SQLite
    def enter_meaning(self, tag):
        for index in self.listbox.curselection():
            esperanto = self.listbox.get(index)
            results = self.cur.execute("SELECT English FROM Words WHERE
Esperanto = ?", (esperanto))
            for row in results:
                self.textbox.delete(1.0, tk.END)
                self.textbox.insert(tk.END, row)

    def entry_delete(self, tag):
        self.entry_search.delete(0, tk.END)
        return None

    def entry_insert(self, tag):
        self.entry_search.delete(0, tk.END)
        self.entry_search.insert(0, "Type to Search")
        return None

def main():
    root = tk.Tk()
    esperantodict = EsperantoDict(root)

if __name__ == '__main__': main()

More information about the Tutor mailing list