-1

i am developing a dictionary app with tkinter. i have some words and their meanings stored in sqlite database in which one of the word is written like "XML", "Access". Now, whenever i input a word like (xml or Xml or ACCESS or access) in entry widget and click the search button, it says "word not found". i want the word to ignore any case sensitivity. i want the meaning of a word to show up whether i type the word like "xml" or "Xml" or "ACCESS" or "access"

import tkinter as tk
import sqlite3
from tkinter import messagebox
from ttkthemes import ThemedStyle
from tkinter import ttk
from PIL import ImageTk, Image
import os
import sys


########### DEF FOR SEARCH #######
def search(event=''):
    if getattr(sys, 'frozen', False):
        data_folder=sys._MEIPASS
    else:
        data_folder=os.getcwd()

    conn = sqlite3.connect(os.path.join(data_folder,'GI_DICTION4.db'))
    cur = conn.cursor()
    tex.delete(1.0, "end")
    data = v.get().swapcase()
    cur.execute("SELECT Meaning FROM Tables2 WHERE Words= ?", (data.swapcase(),))
    var = cur.fetchall()

    if var:
        tex.insert("end", var[0])  # accessing the meaning
    else:
         tex.insert("end","Word not found")



def refresh():
    entry.delete(0, "end")
    tex.delete(1.0, "end")


def fetch_data(word):
    if getattr(sys, 'frozen', False):
        data_folder=sys._MEIPASS
    else:
        data_folder=os.getcwd()
    conn = sqlite3.connect(os.path.join(data_folder,'GI_DICTION4.db'))
    cur = conn.cursor()
    cur.execute("select Words from Tables2 where Words like ? || '%'", (word,))
    allw = cur.fetchall()
    return allw


def on_key_release(event):
    qword = event.widget.get()
    allw = fetch_data(qword)
    listbox.delete(0, tk.END)
    for w in allw:
        listbox.insert(tk.END, w[0])


def on_select(event):
    entry.delete(0, tk.END)
    entry.insert(0, event.widget.selection_get())


########## GUI DESIGN ##############
Temitope
  • 27
  • 5

1 Answers1

0

Is the data in your table all stored in one case e.g lower case or upper case.

  • If Yes, then you can convert the python string to either using string.lower() or string.upper() functions.
  • You can also use COLLATE NOCASE in your SQL query to ignore case of the word.

    SELECT Meaning FROM Tables2 WHERE words = 'XML' COLLATE NOCASE

Check this answer - How to set Sqlite3 to be case insensitive when string comparing?

VTi
  • 1,309
  • 6
  • 14