EmaSMach

together

Apr 16th, 2020
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.24 KB | None | 0 0
  1. import tkinter as tk
  2. import sqlite3
  3. from tkinter import messagebox
  4.  
  5. ########### DEF FOR SEARCH #######
  6.  
  7.  
  8. def search():
  9.     conn = sqlite3.connect('GIS_DICTION.db')
  10.     cur = conn.cursor()
  11.     tex.delete(1.0, "end")
  12.     data = v.get()
  13.     cur.execute("SELECT Meaning, Image FROM DICTION WHERE Words= ?", (data,))
  14.     var = cur.fetchone()
  15.     if var:
  16.         tex.insert("end", var[0])  # accessing the meaning
  17.     else:
  18.         messagebox.showinfo("Dic", "Word not found")
  19.  
  20.     # get data from test_lis
  21.     # update data in listbox
  22.  
  23.     #####################################
  24.     # img_path = var[1]                            # accessing the path to the image
  25.     # image_object = tk.PhotoImage(file=img_path)  # here I'm not using PIL, but tkinter PhotoImage
  26.     # ImageLabel.config(image=image_object)
  27.     # ImageLabel.image = image_object              # keep a reference to the image
  28.     ######################################
  29.  
  30.  
  31. def refresh():
  32.     entry.delete(0, "end")
  33.     tex.delete(1.0, "end")
  34.  
  35.  
  36. def fetch_data(word):
  37.     conn = sqlite3.connect('GIS_DICTION.db')
  38.     cur = conn.cursor()
  39.     cur.execute("select Words from DICTION where Words like ? || '%'", (word,))
  40.     allw = cur.fetchall()
  41.     return allw
  42.  
  43.  
  44. def on_key_release(event):
  45.     qword = event.widget.get()
  46.     allw = fetch_data(qword)
  47.     listbox.delete(0, tk.END)
  48.     for w in allw:
  49.         listbox.insert(tk.END, w[0])
  50.  
  51.  
  52. def on_select(event):
  53.     entry.delete(0, tk.END)
  54.     entry.insert(0, event.widget.selection_get())
  55. ########## GUI DESIGN ##############
  56.  
  57.  
  58. def dictionary_window():
  59.     global tex
  60.     global v
  61.     global entry
  62.     dictWin = tk.Toplevel()
  63.     # to the top, so it can be referrenced
  64.     global listbox
  65.     listbox = tk.Listbox(dictWin, width=35)
  66.     ########
  67.     dictWin.geometry("600x500")
  68.     dictWin.resizable(width=True, height=True)
  69.     dictWin.title("Dic")
  70.     dictWin.configure(background="#E0E0E0")
  71.     v = tk.StringVar()
  72.     entry = tk.Entry(dictWin, width=20, font=(
  73.         "Bahnschrift SemiLight", 11), bg="#FFFFFf", bd=2, textvariable=v)
  74.     entry.place(x=50, y=25)
  75.  
  76.     Butt = tk.Button(dictWin, width=10, height=1, command=search,
  77.                      text="Search", bg="#666699", fg="white", bd=0, font=("rockwell", 10))
  78.     Butt.place(x=220, y=25)
  79.     Refr = tk.Button(dictWin, width=10, height=1, command=refresh,
  80.                      text="Refresh", bg="#666699", fg="white", bd=0, font=("rockwell", 10))
  81.     Refr.place(x=300, y=25)
  82.     tex = tk.Text(dictWin, font=("Bahnschrift SemiLight", 12),
  83.                   bg="#999ccc", bd=0, width=35, height=10)
  84.     tex.place(x=50, y=55)
  85.     frame = tk.Frame(dictWin,  bg="white")
  86.     frame.place(x=40, y=250)
  87.     ImageLabel = tk.Label(frame, font=("calibra", 9), bg="white")
  88.     ImageLabel.pack(expand=True, fill=tk.BOTH, padx=65, pady=20)
  89.  
  90.     ########testingAuto############
  91.     # listbox = tk.Listbox(dictWin, width=35)
  92.     listbox.place(x=370, y=70)
  93.     # listbox.bind('<Double-Button-1>', on_select)
  94.     listbox.bind('<<ListboxSelect>>', on_select)
  95.     entry.bind('<KeyRelease>', on_key_release)
  96.     allw = fetch_data('')
  97.     for w in allw:
  98.         listbox.insert(tk.END, w[0])
  99.     dictWin.mainloop()
  100.  
  101.  
  102. if __name__ == '__main__':
  103.     dictionary_window()
Advertisement
Add Comment
Please, Sign In to add comment