EmaSMach

Help on displaying images (tkinter - Python)

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