Tkinter

by: victorsuliah, 7 years ago


#Level : beginner
#Please i want to create as python gui in tkinter to search a database and display the results.
#but the problem i am facing is how to display the data if it returns many rows.







from tkinter import *
from tkinter import ttk
import sqlite3

conn = sqlite3.connect('meandyou.db')
c = conn.cursor()



root = Tk()

frame = ttk.Frame(root)
frame.pack(anchor = 'nw')
logo = PhotoImage(file = 'python_images/water.png').subsample(5, 5)
##logo.subsample(5, 5)
label = ttk.Label(frame, image = logo)
label.grid(row = 0, column = 0,columnspan = 2, rowspan =2)

label2 = ttk.Label(frame , text = "EASY RETRIVAL", font = ('Arial', 18, 'bold'))
label2.grid(row = 0, column =2)

label3 = ttk.Label(frame, text ="Search By:", font  = ('Arial', 18, 'bold'))
label3.grid(row = 2, column = 0)

var1 = StringVar()
var2 = StringVar()
var3 = StringVar()

ttk.Checkbutton(frame, text="Author", variable = var1).grid(row = 3, column =1, sticky = 'nw',padx = 4, pady = 4)
ttk.Checkbutton(frame, text="Title", variable = var2).grid(row = 4, column =1, sticky = 'nw',padx = 4, pady = 4)
ttk.Checkbutton(frame, text="Keyword In title", variable = var3).grid(row = 5, column =1, sticky = 'nw',padx = 4, pady = 4)


ent1 = ttk.Entry(frame, width =70)
ent1.grid(row = 6, column = 0, columnspan = 3, sticky = 'ne', pady = 4)



def retrive():
    results = (ent1.get(),)
    c.execute("SELECT * FROM new WHERE name = (?)",results)
    data = c.fetchall()
    for row in data:
        print(row)
    conn.commit()
        
btn = ttk.Button(frame, text="Search", width =20,command = retrive)
btn.grid(row = 6, column = 4,padx = 4, pady = 4,sticky = 'ne')

labe = ttk.Label(frame, text = "Results", font= ('Arial', 14, 'bold'))
labe.grid(row = 7, column = 0,padx = 4, pady = 4)
frame2 = ttk.Frame(root,borderwidth = 2, relief = SUNKEN, width =400, height= 100)
frame2.pack(anchor = 'w',padx = 4, pady = 4)

l1 = ttk.Label(frame2, text= 'Name')
l1.grid(row = 0, column =0,padx = 20)

l2 = ttk.Label(frame2, text= 'Amount')
l2.grid(row = 0, column =1,padx = 20)

l3 = ttk.Label(frame2, text= 'Type')
l3.grid(row = 0, column =2,padx = 20)
##lab = ttk.Label(frame2, text = "Search Results",font = ('Arial', 15, 'bold'))
##lab.grid(row = 0, column =0, sticky = 'nw')
##labw = ttk.Label(frame2, text = "this is a test")
##labw.grid(row = 1, column =0)

root.mainloop()




You must be logged in to post. Please login or register an account.