Tkinter entry output - python

I am creating a Data finder using a db file and i use tkinter entry. however in the console it returns the output [] and the code is this
import sqlite3
import tkinter
db = sqlite3.connect ('covidjakartadb.db')
window = tkinter.Tk()
window.geometry("500x300")
label = tkinter.Label(window, text="Please enter a area")
label.pack()
entry = tkinter.Entry(window)
entry.pack()
select_all = "SELECT * FROM locations WHERE '%{0}%'".format(entry)
cursor = sqlite3.Cursor(db)
cursor.execute(select_all)
def Search_Completed():
label = tkinter.Label(window, text="aaaaa")
Button = tkinter.Button(window, text="Search data", command=Search_Completed)
Button.pack()
positive = cursor.fetchall()
print (positive)
window.mainloop()
This project is due today so a answer today would be greatful

The code to select from the database needs to be in the search_completed function. As written it runs before the GUI is even open.
The search should be using the contents of the Entry, entry.get() not entry.
import sqlite3
import tkinter
db = sqlite3.connect ('covidjakartadb.db')
window = tkinter.Tk()
window.geometry("500x300")
label = tkinter.Label(window, text="Please enter a area")
label.pack()
entry = tkinter.Entry(window)
entry.pack()
def Search_Completed():
# select_all = "SELECT * FROM locations WHERE '%{0}%'".format(entry)
# select_all = "SELECT * FROM locations WHERE '%{0}%'".format( entry.get() )
# This will work
select_all = "SELECT * FROM locations WHERE City LIKE '%{0}%'".format( entry.get() )
# Or this.
# select_all = "SELECT * FROM locations WHERE City == '{0}'".format( entry.get() )
cursor = sqlite3.Cursor(db)
cursor.execute(select_all)
positive = cursor.fetchall()
print (positive)
label = tkinter.Label(window, text="aaaaa")
Button = tkinter.Button(window, text="Search data", command=Search_Completed)
Button.pack()
window.mainloop()
I'm unable to test the code as I don't have the database so this may have a few errors in it.

Related

make modifications instantly in tkinter

I created a program used by several users via a hosting system.
The purpose of this program is when a user A click on the button change value, the buttons Color change and Generate text change state ( normal to disable) instantly.
The users B must see the changement when they click on the tab 1 without restarting the program. The users don't have to restart the program to see the change. But here, my code works but the users have to restart the program to see the change made by other users...
I don't want that. Is there any solution?
Thank you
from tkinter import *
import tkinter as tk
from tkinter import ttk
from tkinter.ttk import *
import sqlite3
root = Tk()
conn = sqlite3.connect( '/database' )
c = conn.cursor()
query = "SELECT var FROM state WHERE id=1"
c.execute( query )
var = c.fetchall()[0][0]
tab = ttk.Notebook( root ) # create notebook
tab.pack( expand = True, fill = tk.BOTH )
def changevalue() :
global var
query = "SELECT var FROM state WHERE id=1"
c.execute( query )
var = c.fetchall()[0][0]
if var == 1 :
query = "UPDATE state SET var=0 WHERE id=1"
conn.execute( query )
conn.commit()
button_1['state'] = 'normal'
button_2['state'] = 'normal'
if var == 0 :
query = "UPDATE state SET var=1 WHERE id=1"
conn.execute( query )
conn.commit()
button_1['state'] = 'disabled'
button_2['state'] = 'disabled'
# create Frames for tab
frame1 = ttk.Frame( tab )
frame1.pack( fill = "both" )
frame2 = ttk.Frame( tab )
frame2.pack( fill = "both" )
frame3 = ttk.Frame( tab )
frame3.pack( fill = "both" )
# Add frames
tab.add( frame1, text = 'Mytab1' )
tab.add( frame2, text = 'Mytab2' )
tab.add( frame3, text = 'Mytab3' )
# Button in each tab
button_1 = Button( frame1, text = "Color change" ).pack()
button_2 = Button( frame2, text = "Generate text" ).pack()
button_3 = Button( frame3, text = "change value", command = changevalue ).pack()
if var == 1 :
button_1 = Button( frame1, text = "Color change", state = 'disabled' )
button_2 = Button( frame2, text = "Generate text", state = 'disabled' )
else :
button_1 = Button( frame1, text = "Color change", state = 'normal' )
button_2 = Button( frame2, text = "Generate text", state = 'normal' )
root.mainloop()
Since you have used sqlite3 table to share the state across processes, you should check the table and update the state of the buttons periodically using after().
Below is a modified code:
import tkinter as tk
from tkinter import ttk
import sqlite3
conn = sqlite3.connect("/database")
c = conn.cursor()
def get_value():
c.execute("SELECT var FROM state WHERE id = 1")
return c.fetchone()[0]
def change_value():
c.execute("UPDATE state SET var = 1 - var WHERE id = 1")
conn.commit()
def check_value():
state = 'disabled' if get_value() == 1 else 'normal'
button_1.config(state=state)
button_2.config(state=state)
root.after(100, check_value)
root = tk.Tk()
tab = ttk.Notebook(root)
tab.pack(fill='both', expand=1)
frame1 = ttk.Frame(tab)
frame2 = ttk.Frame(tab)
frame3 = ttk.Frame(tab)
tab.add(frame1, text='Mytab1')
tab.add(frame2, text='Mytab2')
tab.add(frame3, text='Mytab3')
button_1 = ttk.Button(frame1, text='Color change')
button_1.pack()
button_2 = ttk.Button(frame2, text='Generate text')
button_2.pack()
ttk.Button(frame3, text='Change value', command=change_value).pack()
check_value() # check value and update state of buttons periodically
root.mainloop()
Note that:
better to avoid using from xxx import *
you don't need to call .pack() on those frames
you should split button_1 = Button(...).pack() into two lines, same applies on button_2

How do I delete or edit records from data base

I apologize in advance for my bad English...
I am new in the programming world so I don't really know what I'm doing. I'm trying to make a basic address book in Python, Tkinter. I managed somehow to write code to add records in the database but cannot write it to delete or edit selected records. Help would be appreciate
import datetime
import tkinter
from tkinter import *
import tkinter as tk
from tkinter import ttk
from PIL import Image, ImageTk
import sqlite3
def date_for_humans():
date = datetime.datetime.now().date()
date = str(date)
x = date.split("-")
return x[2] + "." + x[1] + "." + x[0] + "."
# creating windows for show contact
def add():
kontakti = Toplevel()
kontakti.title("Lista kontakta")
kontakti.iconbitmap(r"phonebookicon.ico")
kontakti.geometry("400x500")
kontakti.resizable(False, False)
def submit():
# create data base or connect to one
conn = sqlite3.connect("Imenik.db")
# create cursor
c = conn.cursor()
# insert into a table
c.execute("INSERT INTO Kontakti VALUES (:f_name, :l_name, :number)",
{
"f_name": f_name.get(),
"l_name": l_name.get(),
"number": number.get()
})
# commint changes
conn.commit()
conn.close()
f_name.delete(0,END)
l_name.delete(0, END)
number.delete(0, END)
# creating and coloring top frame
topframe = tk.Frame(kontakti, height=150, bg="#ffffff")
topframe.pack(fill=X)
# creating and coloring bottom farame
bottomframe = tk.Frame(kontakti, height=350, bg="#34ebeb")
bottomframe.pack(fill=X)
# creating text at the top of app:
text2 = Label(kontakti, text="DODAVANJE KONTAKTA", font="ariel 15 bold", bg="#ffffff", fg="black")
text2.place(x=80, y=20)
# creating close button
button1 = Button(kontakti, text="Zatvori prozor", bg="white", fg="black",
activebackground="#A9A9A9", font=("Helvetica", 10, "bold"), command=kontakti.destroy)
button1.place(x=295, y=465)
# create text boxes
f_name = Entry(kontakti, width=30)
f_name.place(x=80, y=200, height=20)
l_name = Entry(kontakti, width=30)
l_name.place(x=80, y=230, height=20)
number = Entry(kontakti, width=30)
number.place(x=80, y=260, height=20)
# create text box labels
f_name_label = Label(kontakti, text="Ime", bg="#34ebeb")
f_name_label.place(x=20, y=200)
l_name_label = Label(kontakti, text="Prezime", bg="#34ebeb")
l_name_label.place(x=20, y=230)
number_label = Label(kontakti, text="Broj", bg="#34ebeb")
number_label.place(x=20, y=260)
# create sumbit button
submint_btn = Button(kontakti, text="Dodaj kontakt", bg="white", fg="black",
activebackground="#A9A9A9", font=("Helvetica", 10, "bold"), command=submit)
submint_btn.place(x=40, y=320)
def edit():
c.execute("UPDATE Kontakti SET f_name=?, l_name=?, number=? WHERE f_name= ? AND l_name = ? AND number=?",
(new_value_for_f_name, new_value_for_l_name, new_value_for_number, f_name, l_name, number))
conn.commit()
def delete():
f_name = listbox.curselection()[0]
l_name = listbox.curselection()[1]
number = listbox.curselection()[2]
c.execute("DELETE * FROM Kontakti WHERE f_name = ? AND l_name = ? AND number = ?", (f_name, l_name, number))
conn.commit()
def leave():
root.destroy()
# creating a main window:
root = Tk()
root.title("Imenik App")
root.iconbitmap(r"phonebookicon.ico")
root.geometry("650x550")
root.resizable(False, False)
# creating and coloring top frame:
topFrame = tk.Frame(root, height=150, bg="#ffffff")
topFrame.pack(fill=X)
# creating and coloring bottom frame:
bottomFrame = tk.Frame(root, height=500, bg="#34ebeb")
bottomFrame.pack_propagate(False)
bottomFrame.pack(fill=X)
listbox = Listbox(bottomFrame)
listbox.place(x=40, y=40, height=340, width=200)
scrollbar = Scrollbar(bottomFrame)
scrollbar.place(height=340, x=240, y=40)
# Insert elements into the listbox
conn = sqlite3.connect("Imenik.db")
c = conn.cursor()
a = c.execute("SELECT *,oid FROM Kontakti")
records = c.fetchall()
for record in records:
listbox.insert(END, str(record[0]) + " " + str(record[1]))
listbox.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=listbox.yview)
# creating text at the top of app:
text1 = Label(root, text="IMENIK", font="ariel 35 bold", bg="#ffffff", fg="black")
text1.place(x=240, y=40)
# displaying date and time at the top of app:
datel = Label(root, text="Danasnji datum: " + date_for_humans(), font="ariel 10 bold", bg="#ffffff", fg="black")
datel.place(x=450, y=125)
# displaying icon at the top of the app:
image1 = Image.open("phonebook1.png")
image1 = image1.resize((90, 90), Image.ANTIALIAS)
image = ImageTk.PhotoImage(image1)
label1 = tkinter.Label(image=image, bg="#ffffff")
label1.image = image
label1.place(x=80, y=30)
conn.commit()
conn.close()
'''
# create data base or connect to one
conn = sqlite3.connect("Imenik.db")
# create cursor
c = conn.cursor()
# create table
c.execute("""CREATE TABLE kontakti (
first_name txt,
last_name txt,
number integer
)""")
# commint changes
conn.commit()
conn.close()
'''
# adding button 1, add contacts
viewButton = Button(root, text="Dodaj kontakt", pady=10, padx=70, bg="white", fg="black",
activebackground="#A9A9A9", font=("Helvetica", 10, "bold"), command=add)
viewButton.place(x=380, y=200)
# adding button 2, edit contacts
addButton = Button(root, text="Izmeni kontakt", pady=10, padx=67, bg="white", fg="black",
activebackground="#A9A9A9", font=("Helvetica", 10, "bold"), command=edit)
addButton.place(x=380, y=260)
# adding button 3, delete contacts
deleteButton = Button(root, text="Obrisi kontakt", pady=10, padx=70, bg="white", fg="black",
activebackground="#A9A9A9", font=("Helvetica", 10, "bold"), command=delete)
deleteButton.place(x=380, y=320)
# adding button 4, exit button
exitButton = Button(root, text="Izlaz", pady=5, padx=50, bg="white", fg="black",
activebackground="#A9A9A9", font=("Helvetica", 10, "bold"), command=leave)
exitButton.place(x=505, y=510)
root.mainloop()
If anything is unclear please ask I really need help.
Thanks in advance!
Hi and welcome to Stack Overflow. For you to know which data is selected with the mouse, you can use the following way:
name_of_listbox.curselection()
This will return a list of the contents of the rows currently selected. It gives us a list because there is an option to select multiple rows of data in a ListBox.
You can iterate through each and grab the data out of them.
Store the data in a variable and use them for UPDATE and DELETE commands.
EDIT:
For deleting records:
f_name = listbox.curselection()[0]
l_name = listbox.curselection()[1]
number = listbox.curselection()[2]
c1.execute("DELETE * FROM Kontakti WHERE f_name = ? AND l_name = ? AND number = ?", (f_name, l_name, number))
conn1.commit()
For modifying the values:
c1.execute("UPDATE Kontakti SET f_name=?, l_name=?, number=? WHERE f_name= ? AND l_name = ? AND number=?",(new_value_for_f_name,new_value_for_l_name,new_value_for_number, f_name, l_name, number))
conn1.commit()
I quite did not get the way you were selecting first name, last name and number from a single listbox. So I have kept the name of the listbox the same.
You are using literal sql script and basically you can delete and update like below.
An advice ORM (Object Relational Mapping) is more effortless rather than raw query.
For Delete
DELETE <TableName> WHERE Id = <Value>
conn = sqlite3.connect("Imenik.db")
c = conn.cursor()
sql = "DELETE TableName WHERE Id = ?"
id = 1
c.execute(sql, (id,))
For Update
UPDATE <TableName> SET <ColumnName> = <NewValue> WHERE Id = <Value>
conn = sqlite3.connect("Imenik.db")
c = conn.cursor()
sql = "UPDATE TableName SET ColumnName = ? WHERE Id = ?"
id = 1
new_value = 'hello'
# params order left to right (important).
c.execute(sql, (new_value, id))

Can anyone show me how to solve the python gui tkinter with same buttons but working separately in different MySQL tables

The 4 buttons (insert, delete, update, get) worked perfectly when I only have a student table in the MySQL database. after I try to add the faculty and college in Python GUI and run, The 4 buttons won't work.
I created the same 4 buttons under each table in the python GUI.
def insert():
fid = e_fid.get()
fname = e_fname.get();
fsalary = e_fsalary.get();
if(fid=="" or fsalary=="" or fname==""):
MessageBox.showinfo("Insert status", "All fields are required")
else:
con = mysql.connect(host="localhost", user="root", password="", database="test0910")
cursor = con.cursor()
cursor.execute("insert into faculty values('"+ fid + "','"+ fname +"','"+ fsalary +"')")
cursor.execute("commit");
e_fid.delete(0, 'end')
e_fname.delete(0, 'end')
e_fsalary.delete(0, 'end')
show()
MessageBox.showinfo("Insert Status", "Inserted Successfully");
con.close();
def insert():
id = e_id.get()
name = e_name.get();
address = e_address.get();
if(id=="" or name=="" or address==""):
MessageBox.showinfo("Insert status", "All fields are required")
else:
con = mysql.connect(host="localhost", user="root", password="", database="test0910")
cursor = con.cursor()
cursor.execute("insert into student values('"+ id + "','"+ name +"','"+ address +"')")
cursor.execute("commit");
e_id.delete(0, 'end')
e_name.delete(0, 'end')
e_address.delete(0, 'end')
show()
MessageBox.showinfo("Insert Status", "Inserted Successfully");
con.close();
root = Tk()
root.geometry("600x700")
root.title("Python+Tkinter+MySQL")
faculty = Label(root, text='Faculty', font=('bold', 15))
faculty.place(x=130, y=250);
fid = Label(root, text='Enter ID', font=('bold', 10))
fid.place(x=20, y=290);
fname = Label(root, text='Enter Name', font=('bold', 10))
fname.place(x=20, y=320);
fsalary = Label(root, text='Enter Salary', font=('bold', 10))
fsalary.place(x=20, y=350);
e_fid = Entry()
e_fid.place(x=150, y=290)
e_fname = Entry()
e_fname.place(x=150, y=320)
e_fsalary = Entry()
e_fsalary.place(x=150, y=350)
insert = Button(root, text="Insert", font=("italic", 10), bg="white", command=insert)
insert.place(x=40, y=390)
delete = Button(root, text="Delete", font=("italic", 10), bg="white", command=delete)
delete.place(x=100, y=390)
update = Button(root, text="Update", font=("italic", 10), bg="white", command=update)
update.place(x=160, y=390)
get = Button(root, text="Get", font=("italic", 10), bg="white", command=get)
get.place(x=225, y=390)
list = Listbox(root)
list.place(x=360, y=250)
student = Label(root, text='Student', font=('bold', 15))
student.place(x=130, y=470);
id = Label(root, text='Enter ID', font=('bold', 10))
id.place(x=20, y=510);
name = Label(root, text='Enter Name', font=('bold', 10))
name.place(x=20, y=540);
address = Label(root, text='Enter Address', font=('bold', 10))
address.place(x=20, y=570);
e_id = Entry()
e_id.place(x=150, y=510)
e_name = Entry()
e_name.place(x=150, y=540)
e_address = Entry()
e_address.place(x=150, y=570)
insert = Button(root, text="Insert", font=("italic", 10), bg="white", command=insert)
insert.place(x=40, y=610)
delete = Button(root, text="Delete", font=("italic", 10), bg="white", command=delete)
delete.place(x=100, y=610)
update = Button(root, text="Update", font=("italic", 10), bg="white", command=update)
update.place(x=160, y=610)
get = Button(root, text="Get", font=("italic", 10), bg="white", command=get)
get.place(x=225, y=610)
list = Listbox(root)
list.place(x=360, y=470)
show()
root.mainloop()
How do I separate the 4 buttons for each table? Totally there are 12 buttons in my Python GUI (insert, delete, update, get)*3
What python command should I use? Thank you!
Ive tried to fix most of the issues I found with the code, but at first lets focus around your main problem. The ideal way would be to use would be a Combobox like:
from tkinter import ttk
from tkinter import messagebox
.....
choices = ['Choose a table','faculty','student'] #list of options to be showed
combo = ttk.Combobox(root,values=choices,state='readonly') #declaring a combobox
combo.current(0) #setting the default value to first item in the list.
combo.pack()
buttoninsert = Button(root,text='Insert',command=insertdb)
buttoninsert.pack()
Note that here, you only need 1 button for each function.
Then define insertdb() as:
def insertdb():
if combo.get() == 'Choose a table':
messagebox.showerror('Choose!','Choose an option!')
elif combo.get() == 'faculty':
fid = e_fid.get()
fname = e_fname.get()
fsalary = e_fsalary.get()
if fid=="" or fsalary=="" or fname=="":
messagebox.showinfo("Insert status", "All fields are required")
else:
con = mysql.connect(host="localhost", user="root", password="", database="test0910")
cursor = con.cursor()
cursor.execute("insert into faculty values(%s,%s,%s)",(fid,fname,fsalary))
cursor.execute("commit")
e_fid.delete(0, 'end')
e_fname.delete(0, 'end')
e_fsalary.delete(0, 'end')
show()
messageBox.showinfo("Insert Status", "Inserted Successfully");
con.close()
elif combo.get() == 'student':
id = e_id.get()
name = e_name.get();
address = e_address.get();
if id=="" or name=="" or address=="":
messageBox.showinfo("Insert status", "All fields are required")
else:
con = mysql.connect(host="localhost", user="root", password="", database="test0910")
cursor = con.cursor()
cursor.execute("insert into student values(%s,%s,%s)",(id,name,address))
cursor.execute("commit");
e_id.delete(0, 'end')
e_name.delete(0, 'end')
e_address.delete(0, 'end')
show()
messageBox.showinfo("Insert Status", "Inserted Successfully");
con.close()
So I hope you got a basic idea of whats happening. If not, Its like the user should choose an option at first, and then click on the button, only then the rest of the operation take place. Make necessary changes to the code, so that it fits to your needs.
Similarly, go on defining 3 other buttons and 3 functions, for your purpose.
What all have I changed?
You used concatenation for inserting data to the database and hence it is not a safe way and is exposed to sql injections. So i changed those to parametric substituions. Where you use %s as a placeholder. Take a look here for better understanding of these
I noticed that you named functions as insert(),get() and all. Naming as such is not accurate as some tkinter widgets has insert() and delete() methods, so it might cause a confusion to python later on.
Avoid naming variables as list, id as these are inbuilt functions and it will cause a confusion later on, again.
Ive imported messagebox, while i noticed you used Messagebox. Im not sure if tkinter.Messagebox exists and it might throw an error, if not, its fine to use.
You can add more mysql table names to the list choices and it will appear as options on the Combobox. Check out more on Combobox
Why did I say from tkinter import ttk? It is because Combobox is a ttk widget rather than a direct tkinter widget, which means it has a theme applied to it(looks modern).
I tried to explain this as simple as possible, hopefully you get a perfect idea on how to proceed. Do let me know if any errors, or doubts.
Cheers

How do I get the Value of Tkcalendar/Date Entry

hi I am building a GUI where it should be possible to insert your name and your brthday that get´s stored in a sqllite3 database.
I use the Tkcalendar module to let the person choose it´s birthday.
My problem is I don´t know how to read out the Date.
I hope somebody can help me!
import sqlite3
verbindung = sqlite3.connect("Datenbanken/geb3.db")
zeiger = verbindung.cursor()
zeiger.execute("""CREATE TABLE IF NOT EXISTS people3(vorname VARCHAR(20), nachname VARCHAR(30), geburtstag DATE );""")
from tkinter import *
from tkcalendar import Calendar, DateEntry
root = Tk()
def speichern():
zeiger.execute("""INSERT INTO people3 VALUES (?,?,?) """, (eingabefeldvorname.get(), eingabefeldnachname.get(), eingabefelddatum.get()))
Label(root, text = "vorname").pack()
eingabefeldvorname=StringVar()
eingabefeld = Entry(root, textvariable = eingabefeldvorname, bg ="red").pack()
Label(root, text = "nachname").pack()
eingabefeldnachname = StringVar()
eingabefeld = Entry(root, textvariable = eingabefeldnachname, bg ="green").pack()
Label(root, text = "Geburtsdatum")
eingabefelddatum= DateEntry(root, width = 20, textvariable = eingabefelddatum, bg ="yellow").pack()
konpf2 = Button(root, text = "speichern", command = speichern).pack()
root.mainloop()
zeiger.execute("SELECT * FROM people3")
inhalt = zeiger.fetchall()
print(inhalt)
def listeleeren():
zeiger.execute("DELETE FROM people3")
listeleeren()
verbindung.commit()
verbindung.close()```
To get the value of DataEntry, the fuction get_date() works.
Reference: https://pypi.org/project/tkcalendar/#dateentry-widget
also you can use a <<DateEntrySelected>> event which is generated each time the user selects a date with the mouse.
import tkinter as tk
from tkinter import ttk
from tkcalendar import Calendar, DateEntry
def dateentry_view():
def print_sel(e):
print(cal.get_date())
top = tk.Toplevel(root)
ttk.Label(top, text='Choose date').pack(padx=10, pady=10)
cal = DateEntry(top, width=12, background='darkblue',
foreground='white', borderwidth=2)
cal.pack(padx=10, pady=10)
cal.bind("<<DateEntrySelected>>", print_sel)
root = tk.Tk()
ttk.Button(root, text='DateEntry', command=dateentry_view).pack(padx=10, pady=10)
root.mainloop()

Tkinter label widget showing variable two times

I am trying to create a corona tracker using a entry widget except everytime i try to search two times the search result shows two times. Here is the picture.
I have tried deleting the variable when the button widget but it didnt work.
import sqlite3
import tkinter
db = sqlite3.connect ('covidjakartadb.db')
window = tkinter.Tk()
window.geometry("500x300")
window.title("Corona tracker")
label = tkinter.Label(window, text="Please enter a area")
label.pack()
entry = tkinter.Entry(window)
entry.pack()
def Search_Completed():
# select_all = "SELECT * FROM locations WHERE '%{0}%'".format(entry)
select_all = "SELECT positive FROM locations WHERE City LIKE '%{0}%'".format( entry.get() )
cursor = sqlite3.Cursor(db)
cursor.execute(select_all)
positive = cursor.fetchall()
print (positive)
tkinter.Label (window, text=positive, font='Ariel 25 bold').pack()
tkinter.Label (window, text="Tips to fight off the coronavirus")
Button = tkinter.Button(window, text="Search data", command=Search_Completed)
Button.pack()
window.mainloop()
Try this :
import sqlite3
import tkinter
db = sqlite3.connect ('covidjakartadb.db')
window = tkinter.Tk()
window.geometry("500x300")
window.title("Corona tracker")
label = tkinter.Label(window, text="Please enter a area")
label.pack()
entry = tkinter.Entry(window)
entry.pack()
def Search_Completed():
result["text"] = ""
# select_all = "SELECT * FROM locations WHERE '%{0}%'".format(entry)
select_all = "SELECT positive FROM locations WHERE City LIKE '%{0}%'".format( entry.get() )
cursor = sqlite3.Cursor(db)
cursor.execute(select_all)
positive = cursor.fetchall()
print (positive)
result["text"] = positive
Button = tkinter.Button(window, text="Search data", command=Search_Completed)
Button.pack()
result= tkinter.Label (window, text=positive, font='Ariel 25 bold')
result.pack()
window.mainloop()

Categories