Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2020
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.93 KB | None | 0 0
  1. import tkinter as tk
  2. import sqlite3
  3. from tkinter import messagebox
  4. root = tk.Tk()
  5. root.geometry("400x500")
  6. root.resizable(width=True, height= True)
  7. root.title("Dic")
  8. root.configure(background='white')
  9.  
  10. ########### DEF FOR SEARCH #######
  11. def search():
  12.     try:
  13.         conn= sqlite3.connect('GIS_DICTION.db')
  14.         cur= conn.cursor()
  15.         tex.delete(1.0,"end")
  16.         data= v.get()
  17.         cur.execute("SELECT Meaning, Image FROM DICTION WHERE Words= ?", (data.lower(),))
  18.         var= cur.fetchone()
  19.  
  20.         tex.insert("end", var[0])  # accessing the meaning
  21.         #####################################
  22.         img_path = var[1]                            # accessing the path to the image
  23.         image_object = tk.PhotoImage(file=img_path)  # here I'm not using PIL, but tkinter PhotoImage
  24.         ImageLabel.config(image=image_object)
  25.         ImageLabel.image = image_object              # keep a reference to the image
  26.     ######################################
  27.     except:
  28.         messagebox.showinfo("Dic","Word not found")
  29. def refresh():
  30.     entry.delete(0, "end")
  31.     tex.delete(1.0, "end")
  32.  
  33.  
  34.  
  35. ########## GUI DESIGN ##############
  36. v= tk.StringVar()
  37. entry= tk.Entry(root, width=20,font= ("Bahnschrift SemiLight",11), bg= "#FFFFFf",bd=2, textvariable= v)
  38. entry.place(x=50, y= 25)
  39.  
  40. Butt= tk.Button(root, width=10, height= 1,command= search, text= "Search", bg= "#666699",fg="white",bd=0,font=("rockwell", 10))
  41. Butt.place(x=220, y=25)
  42. Refr= tk.Button(root, width=10, height= 1,command= refresh, text= "Refresh", bg= "#666699",fg="white",bd=0,font=("rockwell", 10))
  43. Refr.place(x=300, y=25)
  44. tex=tk.Text(root, font= ("Bahnschrift SemiLight",12),bg= "#999ccc",bd= 0,width=35,height= 10)
  45. tex.place(x=50,y=55)
  46. frame= tk.Frame(root,  bg= "white")
  47. frame.place(x=40, y= 250)
  48. ImageLabel= tk.Label(frame,font=("calibra", 9),  bg= "white")
  49. ImageLabel.pack(expand=True, fill= tk.BOTH,padx= 65, pady=20)
  50.  
  51.  
  52.  
  53. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement