Advertisement
deadmarshal

Untitled

Sep 9th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.92 KB | None | 0 0
  1. #! /usr/bin/env python3
  2. import sqlite3 as sqlite
  3. import tkinter as tk
  4. from tkinter import Listbox
  5. from tkinter import Text
  6. from tkinter import Entry
  7. from tkinter import Scrollbar
  8. from tkinter import ttk
  9.  
  10. #GUI
  11. root = tk.Tk()
  12. #sqlite
  13. db = sqlite.connect(r'/home/deadmarshal/PycharmProjects/Geologydict/test.db')
  14. cur = db.cursor()
  15. cur.execute('select Esperanto from Words')
  16.  
  17.  
  18. def enter_meaning(*args):
  19.     if listbox.curselection():
  20.         cur.execute('select English from Words')
  21.         cur.fetchall()
  22.         for i in cur:
  23.             textbox.insert(tk.END, i)
  24.  
  25. frame1 = ttk.LabelFrame(root)
  26. frame1.config(height=200, width=300, text="Words")
  27. frame1.pack(side=tk.LEFT, anchor='nw')
  28. frame1.config(padding=(3, 5))
  29. frame2 = ttk.LabelFrame(root)
  30. frame2.config(height=200, width=300, text="Definitions")
  31. frame2.pack(side=tk.RIGHT, anchor='ne')
  32. frame2.config(padding=(3, 5))
  33.  
  34. entry = tk.Entry(frame1, width=30)
  35. entry.grid(row=0, column=0)
  36. entry.insert(0, "Type to Search")
  37.  
  38.  
  39. def entry_callback(event):
  40.     entry.delete(0, tk.END)
  41.     return None
  42. entry.bind('<Button-1>', entry_callback)
  43.  
  44. button = ttk.Button(frame1, text="Search")
  45. button.grid(row=0, column=1)
  46. logo = tk.PhotoImage(file='/home/deadmarshal/PycharmProjects/Geologydict/search.png')
  47. small_logo = logo.subsample(3, 3)
  48. button.config(image=small_logo, compound=tk.LEFT)
  49.  
  50. textbox = Text(frame2, width=60, height=34)
  51. textbox.pack()
  52. textbox.config(wrap='word')
  53. listbox = Listbox(frame1, height=30, width=30)
  54. s = Scrollbar(frame1, orient=tk.VERTICAL)
  55. listbox.configure(yscrollcommand=s.set)
  56. listbox.grid(row=1, column=0)
  57. listbox.bind('<<ListboxSelect>>', enter_meaning)
  58.  
  59. for row in cur:
  60.     listbox.insert(tk.END, row)
  61.     if listbox.bind('<Button-1>'):
  62.         cur.execute('select Esperanto from Words')
  63.         textbox.insert(tk.END, cur)
  64.  
  65. #db tbl name: Words
  66. ##db first field name: Esperanto
  67. ##db second field name: English
  68.  
  69. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement