Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- import sqlite3
- from tkinter import messagebox
- ########### DEF FOR SEARCH #######
- def search():
- conn = sqlite3.connect('GIS_DICTION.db')
- cur = conn.cursor()
- tex.delete(1.0, "end")
- data = v.get()
- cur.execute("SELECT Meaning, Image FROM DICTION WHERE Words= ?", (data,))
- var = cur.fetchone()
- if var:
- tex.insert("end", var[0]) # accessing the meaning
- else:
- messagebox.showinfo("Dic", "Word not found")
- # get data from test_lis
- # update data in listbox
- #####################################
- # img_path = var[1] # accessing the path to the image
- # image_object = tk.PhotoImage(file=img_path) # here I'm not using PIL, but tkinter PhotoImage
- # ImageLabel.config(image=image_object)
- # ImageLabel.image = image_object # keep a reference to the image
- ######################################
- def refresh():
- entry.delete(0, "end")
- tex.delete(1.0, "end")
- def fetch_data(word):
- conn = sqlite3.connect('GIS_DICTION.db')
- cur = conn.cursor()
- cur.execute("select Words from DICTION 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 ##############
- def dictionary_window():
- global tex
- global v
- global entry
- dictWin = tk.Toplevel()
- # to the top, so it can be referrenced
- global listbox
- listbox = tk.Listbox(dictWin, width=35)
- ########
- dictWin.geometry("600x500")
- dictWin.resizable(width=True, height=True)
- dictWin.title("Dic")
- dictWin.configure(background="#E0E0E0")
- v = tk.StringVar()
- entry = tk.Entry(dictWin, width=20, font=(
- "Bahnschrift SemiLight", 11), bg="#FFFFFf", bd=2, textvariable=v)
- entry.place(x=50, y=25)
- Butt = tk.Button(dictWin, width=10, height=1, command=search,
- text="Search", bg="#666699", fg="white", bd=0, font=("rockwell", 10))
- Butt.place(x=220, y=25)
- Refr = tk.Button(dictWin, width=10, height=1, command=refresh,
- text="Refresh", bg="#666699", fg="white", bd=0, font=("rockwell", 10))
- Refr.place(x=300, y=25)
- tex = tk.Text(dictWin, font=("Bahnschrift SemiLight", 12),
- bg="#999ccc", bd=0, width=35, height=10)
- tex.place(x=50, y=55)
- frame = tk.Frame(dictWin, bg="white")
- frame.place(x=40, y=250)
- ImageLabel = tk.Label(frame, font=("calibra", 9), bg="white")
- ImageLabel.pack(expand=True, fill=tk.BOTH, padx=65, pady=20)
- ########testingAuto############
- # listbox = tk.Listbox(dictWin, width=35)
- listbox.place(x=370, y=70)
- # listbox.bind('<Double-Button-1>', on_select)
- listbox.bind('<<ListboxSelect>>', on_select)
- entry.bind('<KeyRelease>', on_key_release)
- allw = fetch_data('')
- for w in allw:
- listbox.insert(tk.END, w[0])
- dictWin.mainloop()
- if __name__ == '__main__':
- dictionary_window()
Advertisement
Add Comment
Please, Sign In to add comment