How to delete only one row in tkinter python? - python

when i run app and delete one row is worked but whene i close the app to update, all rows are deleted
what should i do
import sqlite3
from tkinter import *
from tkinter import ttk
class root(Tk):
def __init__(self):
super().__init__()
self.bookInfodb = sqlite3.connect("test.db")
self.c = self.bookInfodb.cursor()
self.bookInfodb.commit()
self.c.execute(
"CREATE TABLE IF NOT EXISTS books (title TEXT, author TEXT, year TEXT, isbn TEXT)")
self.title("book info")
self.minsize(500, 400)
self.configure(background="gray")
self.datas()
self.fetch()
def fetch(self):
self.c.execute("SELECT * FROM books")
rows = self.c.fetchall()
for row in rows:
self.list_box.insert(END, row)
def delete_item(self):
selected_item = self.list_box.curselection()
for item in selected_item:
self.list_box.delete(item)
self.c.execute("DELETE FROM books")
self.bookInfodb.commit()
def addData(self, title, years, author, isbn):
self.c.execute(
"INSERT INTO books VALUES (?,?,?,?)", (
self.title.get(),
self.years.get(),
self.author.get(),
self.isbn.get()))
self.bookInfodb.commit()
def datas(self):
self.title = StringVar()
self.titleEntry = ttk.Label(self, text="titel")
self.titleEntry.place(x=41, y=10)
entry = Entry(self, textvariable=self.title)
entry.place(x=66, y=10)
# make years input
self.years = StringVar()
self.yearsEntry = ttk.Label(self, text="years")
self.yearsEntry.place(x=269, y=10)
entry2 = Entry(self, textvariable=self.years)
entry2.place(x=300.5, y=10.2)
# make author input
self.author = StringVar()
self.authorEntry = ttk.Label(self, text="author")
self.authorEntry.place(x=40, y=51)
entry3 = Entry(self, textvariable=self.author)
entry3.place(x=80, y=51)
# make isbn input
self.isbn = StringVar()
self.isbnEntry = ttk.Label(self, text="isbn")
self.isbnEntry.place(x=270, y=52)
entry_iv = Entry(self, textvariable=self.isbn)
entry_iv.place(x=297, y=52)
# listbox
self.list_box = Listbox(self, height=10, width=50)
self.list_box.place(x=85, y=200)
# buttons
save_button = Button(
self,
text=" save ",
command=(
lambda t=self.title.get(), y=self.years.get(), a=self.author.get(), i=self.isbn: self.addData(t, y, a, i)),)
save_button.place(x=66, y=150)
delete_button = Button(self, text="delete", command=self.delete_item)
delete_button.place(x=215, y=150)
windows = root()
windows.mainloop()

I don't know if this is the problem but self.c.execute("DELETE FROM books") will delete the entire books table.
You probably need to add a WHERE clause in your DELETE statement
self.c.execute("DELETE FROM books WHERE ...")

Related

AttributeError: '_tkinter.tkapp' object has no attribute 'cur'

this is the tkinter app code
import sqlite3
from tkinter import *
from db import db
class root(Tk):
def __init__(self):
super().__init__()
self.title("book info")
self.minsize(500, 400)
self.configure(background="gray")
self.create_data()
self.populate_list()
def create_data(self):
#make title input
self.title = StringVar()
self.titleEntry = Label(self, text="title")
self.titleEntry.place(x=41, y=10)
entry = Entry(self, textvariable=self.title)
entry.place(x=66, y=10)
# make years input
self.years = StringVar()
self.yearsEntry = Label(self, text="years")
self.yearsEntry.place(x=269, y=10)
entry2 = Entry(self, textvariable=self.years)
entry2.place(x=300.5, y=10.2)
# make author input
self.author = StringVar()
self.authorEntry = Label(self, text="author")
self.authorEntry.place(x=40, y=51)
entry3 = Entry(self, textvariable=self.author)
entry3.place(x=80, y=51)
# make isbn input
self.isbn = StringVar()
self.isbnEntry = Label(self, text="isbn")
self.isbnEntry.place(x=270, y=52)
entry_iv = Entry(self, textvariable=self.isbn)
entry_iv.place(x=297, y=52)
# listbox
self.list_box = Listbox(self, height=10, width=50)
self.list_box.place(x=85, y=200)
# buttons
save_button = Button(self,text= "save")
save_button.place(x=66, y=150)
delete_button = Button(self, text="delete")
delete_button.place(x=215, y=150)
search_button = Button(self, text="search")
search_button.place(x=360, y=150)
def populate_list(self):
#clear list
self.list_box.delete(0,END)
rows = db.fetch(self)
for row in rows:
self.list_box.insert(END,row)
win = root()
win.mainloop()
and this is the databace code
import sqlite3
class db():
def __init__(self):
self.cur = conn.cursor("wikibook.db")
self.cur.execute("CREATE TABELE IF NOT EXISTS book (id INTEGER PRIMARY KEY,title TEXT,yearTEXT,author TEXT,isbn INTEGER)")
self.conn.commit()
def fetch(self):
self.cur.execute("SELECT FROM * book")
rows = self.cur.fetchall
return rows
def insert(self, title, year, author, isbn):
self.cur.execute("INSERT INTO book VALUES (id ,? ,?, ?, ?)",(text, year ,author, isbn, id))
self.conn.commit()
def delete(self,id):
self.cur.execute("DELETE FROM books WHERE id=?",(id,))
self.conn.commit()
def update(self ,title, year, author, isbn):
self.cur.execute("UPDATE FROM book (?, ?, ?, ?)",(title ,year ,author ,isbn))
self.conn.commit()
def search(self):
self.cur.execute("SELECT* FROM book WHERE title = ? and author = ? and year = ? and isbn = ?", (title ,year ,author ,isbn))
rows = self.cur.fetchall()
return rows
def __del__(self):
self.conn.close()
I hope this helps to solve the problem

i got this error sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type. how can i fix it

this my cod
import sqlite3
from tkinter import *
from tkinter import ttk
class root(Tk):
def __init__(self):
super().__init__()
self.bookInfodb = sqlite3.connect("data.db")
self.c = self.bookInfodb.cursor()
self.bookInfodb.commit()
self.c.execute(
"CREATE TABLE IF NOT EXISTS books (title TEXT, author TEXT, year TEXT, isbn TEXT)"
)
self.title("book info")
self.minsize(500, 320)
self.configure(background="gray")
self.datas()
def addData(self, title, years, author, isbn):
self.c.execute(
"INSERT INTO books VALUES (?,?,?,?)",
([title, years, author, isbn]),
)
self.bookInfodb.commit()
def datas(self):
self.title = StringVar()
self.titleEntry = ttk.Label(self, text="titel")
self.titleEntry.place(x=41, y=10)
entry = Entry(self, textvariable=self.title)
entry.place(x=66, y=10)
# make years input
self.years = IntVar()
self.yearsEntry = ttk.Label(self, text="years")
self.yearsEntry.place(x=269, y=10)
entry2 = Entry(self, textvariable=self.years)
entry2.place(x=300.5, y=10.2)
# make author input
self.author = StringVar()
self.authorEntry = ttk.Label(self, text="author")
self.authorEntry.place(x=40, y=51)
entry3 = Entry(self, textvariable=self.author)
entry3.place(x=80, y=51)
# make isbn input
self.isbn = IntVar()
self.isbnEntry = ttk.Label(self, text="isbn")
self.isbnEntry.place(x=270, y=52)
entry_iv = Entry(self, textvariable=self.isbn)
entry_iv.place(x=297, y=52)
# buttons
save_button = Button(
self,
text=" save ",
command=(
lambda t=self.title, y=self.years, a=self.author, i=self.isbn: self.addData(
t, y, a, i
)
),
)
save_button.place(x=66, y=150)
delete_button = Button(self, text="delete")
delete_button.place(x=215, y=150)
search_button = Button(self, text="search")
search_button.place(x=360, y=150)
windows = root()
windows.mainloop()
As typedecker's comment says, you'd need to read the actual values out of the Tk variables. Since you're storing the vars on the instance anyway, you don't need to pass them to the addData function separately. The datas function is also extraneous, and I took the liberty of renaming things so labels are labels and entries are entries, the main class is more sanely named, and getting rid of the wildcard import.
import sqlite3
from tkinter import ttk, StringVar, IntVar, Tk, Entry, Button
class BookApp(Tk):
def __init__(self):
super().__init__()
self.bookInfodb = sqlite3.connect("data.db")
self.bookInfodb.execute(
"CREATE TABLE IF NOT EXISTS books (title TEXT, author TEXT, year TEXT, isbn TEXT)"
)
self.title("book info")
self.minsize(500, 320)
self.configure(background="gray")
self.title_var = StringVar()
self.years_var = IntVar()
self.author_var = StringVar()
self.isbn_var = StringVar()
# make title input
title_label = ttk.Label(self, text="titel")
title_label.place(x=41, y=10)
title_entry = Entry(self, textvariable=self.title_var)
title_entry.place(x=66, y=10)
# make years input
years_label = ttk.Label(self, text="years")
years_label.place(x=269, y=10)
years_entry = Entry(self, textvariable=self.years_var)
years_entry.place(x=300.5, y=10)
# make author input
author_label = ttk.Label(self, text="author")
author_label.place(x=40, y=51)
author_entry = Entry(self, textvariable=self.author_var)
author_entry.place(x=80, y=51)
# make isbn input
isbn_label = ttk.Label(self, text="isbn")
isbn_label.place(x=270, y=52)
isbn_entry = Entry(self, textvariable=self.isbn_var)
isbn_entry.place(x=297, y=52)
# buttons
save_button = Button(
self,
text=" save ",
command=self.addData,
)
save_button.place(x=66, y=150)
delete_button = Button(self, text="delete")
delete_button.place(x=215, y=150)
search_button = Button(self, text="search")
search_button.place(x=360, y=150)
def addData(self):
self.bookInfodb.execute(
"INSERT INTO books VALUES (?,?,?,?)",
(
self.title.get(),
self.author_var.get(),
self.years_var.get(),
self.isbn_var.get(),
),
)
self.bookInfodb.commit()
app = BookApp()
app.mainloop()
The error occurs, because you are trying to store an object of tkinter.StringVar, in your sql database.
Since, self.title has been declared as an object of the tkinter.StringVar class here -:
self.title = StringVar()
but, when you store it in your database, perhaps what you want to store, is the string value of the self.title, stringvar, which can be fetched using the .get() method of tkinter.StringVar like so -:
title_value = self.title.get()
Also, since author, years, and all other fields of data being stored into the database, but have been defined as a tkinter.StringVar, the same procedure will have to be followed for all of them.
So, by changing the arguments passed to the function call to the addData() function call, you can fix the problem, like so -:
save_button = Button(
self,
text=" save ",
command=(
lambda t=self.title.get(), y=self.years.get(), a=self.author.get(), i=self.isbn: self.addData(
t, y, a, i
)
),
)
NOTE:
You can also, alternatively, modify your addData() method to accept tkinter.StringVar type as parameters but then fetch the value when executing the query like so -:
def addData(self, title, years, author, isbn):
self.c.execute(
"INSERT INTO books VALUES (?,?,?,?)",
([title.get(), years.get(), author.get(), isbn.get()]),
)
self.bookInfodb.commit()
Further, as suggested by #AKX in his answer, some modifications to your code can make it look neater, shorter, and perhaps prevent other errors, that are possible due to wildcard imports.

function call from a function to a function within a class fails

I'm trying to setup a program where my tkinter GUI functions are in a class and my database functions are in another class. I have a function external to both classes that fails when I try to call a function within the DB class. Can you help me resolve this error? Should both my GUI and any database be in separate functions or is that a poor design. The attached code is a stripped down version to illustrates my issue. Clicking the "View all" button generates the error.
import sqlite3
from tkinter import *
from tkinter import messagebox
class DB:
def __init__(self):
self.conn = sqlite3.connect("mybooks.db")
self.cur = self.conn.cursor()
self.cur.execute(
"CREATE TABLE IF NOT EXISTS book (id INTEGER PRIMARY KEY, title TEXT, author TEXT, isbn INTEGER)")
self.conn.commit()
def __del__(self):
self.conn.close()
def view(self):
self.cur.execute("SELECT * FROM book")
rows = cur.fetchall()
return rows
def view_command():
# there is a problem with the next line
# when rows=DB.view() error is TypeError: view() missing 1 required positional argument: 'self'
# when rows=DB.view(self) error is NameError: name 'self' is not defined
rows=DB.view(self)
for row in rows:
print(row)
class App_GUI(): # create the main window
def __init__(self, master):
self.master = master
self.master.title("My Books")
self.master.l1 = Label(self.master, text="Title")
self.master.l1.grid(row=0, column=0)
self.master.l2 = Label(self.master, text="Author")
self.master.l2.grid(row=0, column=2)
self.master.l3 = Label(self.master, text="ISBN")
self.master.l3.grid(row=1, column=0)
self.master.title_text = StringVar()
self.master.e1 = Entry(self.master, textvariable=self.master.title_text)
self.master.e1.grid(row=0, column=1)
self.master.author_text = StringVar()
self.master.e2 = Entry(self.master, textvariable=self.master.author_text)
self.master.e2.grid(row=0, column=3)
self.master.isbn_text = StringVar()
self.master.e3 = Entry(self.master, textvariable=self.master.isbn_text)
self.master.e3.grid(row=1, column=1)
self.master.list1 = Listbox(self.master, height=6, width=35)
self.master.list1.grid(row=2, column=0, rowspan=6, columnspan=2)
self.master.sb1 = Scrollbar(self.master)
self.master.sb1.grid(row=2, column=2, rowspan=6)
self.master.list1.configure(yscrollcommand=self.master.sb1.set)
self.master.sb1.configure(command=self.master.list1.yview)
self.master.b1 = Button(self.master, text="View all", width=12, command=view_command)
self.master.b1.grid(row=2, column=3)
self.master.b6 = Button(self.master, text="Close", width=12, command=self.master.destroy)
self.master.b6.grid(row=7, column=3)
return
###############################
# Program Main #
###############################
def main():
db = DB()
root = Tk()
def on_closing():
dd = db
if messagebox.askokcancel("Quit", "Do you want to close the application"): # ask the user if he/she wants to close the application
root.destroy()
del dd
root.protocol("WM_DELETE_WINDOW", on_closing) # catch the user closing the window
app = App_GUI(root) # creation of an instance
root.mainloop() # tkinter mainloop
if __name__ == '__main__':
main()
````
You need to pass db to App_GUI and then on to the function:
def view_command(db):
rows = db.view()
for row in rows:
print(row)
class App_GUI(): # create the main window
def __init__(self, master, db):
# other stuff elided ...
self.master.b1 = Button(self.master, text="View all", width=12, command=lambda : view_command(db))
...
def main():
db = DB()
# other stuff elided
app = App_GUI(root, db)
edit: forgot to remove self.
I figured it out! In addition to your changes, I had to remove 'self' from rows=db.view(). Thanks for your help! Revised code:
import sqlite3
from tkinter import *
from tkinter import messagebox
class DB:
def __init__(self):
self.conn = sqlite3.connect("mybooks.db")
self.cur = self.conn.cursor()
self.cur.execute(
"CREATE TABLE IF NOT EXISTS book (id INTEGER PRIMARY KEY, title TEXT, author TEXT, isbn INTEGER)")
self.conn.commit()
def __del__(self):
self.conn.close()
def view(self):
self.cur.execute("SELECT * FROM book")
rows = self.cur.fetchall()
return rows
def view_command(db):
rows=db.view()
for row in rows:
print(row)
class App_GUI(): # create the main window
def __init__(self, master, db):
self.master = master
self.master.title("My Books")
self.master.l1 = Label(self.master, text="Title")
self.master.l1.grid(row=0, column=0)
self.master.l2 = Label(self.master, text="Author")
self.master.l2.grid(row=0, column=2)
self.master.l3 = Label(self.master, text="ISBN")
self.master.l3.grid(row=1, column=0)
self.master.title_text = StringVar()
self.master.e1 = Entry(self.master, textvariable=self.master.title_text)
self.master.e1.grid(row=0, column=1)
self.master.author_text = StringVar()
self.master.e2 = Entry(self.master, textvariable=self.master.author_text)
self.master.e2.grid(row=0, column=3)
self.master.isbn_text = StringVar()
self.master.e3 = Entry(self.master, textvariable=self.master.isbn_text)
self.master.e3.grid(row=1, column=1)
self.master.list1 = Listbox(self.master, height=6, width=35)
self.master.list1.grid(row=2, column=0, rowspan=6, columnspan=2)
self.master.sb1 = Scrollbar(self.master)
self.master.sb1.grid(row=2, column=2, rowspan=6)
self.master.list1.configure(yscrollcommand=self.master.sb1.set)
self.master.sb1.configure(command=self.master.list1.yview)
self.master.b1 = Button(self.master, text="View all", width=12, command=lambda : view_command(db))
self.master.b1.grid(row=2, column=3)
self.master.b6 = Button(self.master, text="Close", width=12, command=self.master.destroy)
self.master.b6.grid(row=7, column=3)
return
###############################
# Program Main #
###############################
def main():
db = DB()
root = Tk()
def on_closing():
dd = db
if messagebox.askokcancel("Quit", "Do you want to close the application"): # ask the user if he/she wants to close the application
root.destroy()
del dd
root.protocol("WM_DELETE_WINDOW", on_closing) # catch the user closing the window
app = App_GUI(root, db) # creation of an instance
root.mainloop() # tkinter mainloop
if __name__ == '__main__':
main()

Select listbox items with button (tkinter)

when i click on each of the items in listbox, a text is printed which comes from db in the Textbox widget of my app. i want to be able to do exactly that also with my button. I mean, when user searches the word in entrybox and the list lowers down to 1 item, i want to be able to select that item with 3 ways (clicking on it in the list, clicking on my button, pressing the Return key on my keyboard). now clicking works. how should i config the button event in enter_meaning function?
import sqlite3 as sqlite
import tkinter as tk
from tkinter import ttk
# GUI Widgets
class EsperantoDict:
def __init__(self, master):
self.search_var = tk.StringVar()
self.search_var.trace("w", lambda name, index, mode: self.update_list())
self.frame_header = ttk.Frame(master, relief=tk.FLAT)
self.frame_header.config(style="TFrame")
self.frame_header.pack(side=tk.TOP, padx=5, pady=5)
ttk.Label(self.frame_header, image=self.small_logo).grid(row=0, column=0, stick="ne", padx=5, pady=5, rowspan=2)
ttk.Label(self.frame_header, text='EsperantoDict', font=('Arial', 18, 'bold')).grid(row=0, column=1)
self.frame_content = ttk.Frame(master)
self.frame_content.config(style="TFrame")
self.frame_content.pack()
self.entry_search = ttk.Entry(self.frame_content, textvariable=self.search_var, width=30)
self.entry_search.bind('<FocusIn>', self.entry_delete)
self.entry_search.bind('<FocusOut>', self.entry_insert)
self.entry_search.grid(row=0, column=0, padx=5)
self.entry_search.focus()
self.entry_search.bind("<KeyRelease>", self.edit_input)
self.button_search = ttk.Button(self.frame_content, text=u"Serĉu", command=self.enter_meaning)
self.photo_search = tk.PhotoImage(file=r'C:\EsperantoDict\search.png')
self.small_photo_search = self.photo_search.subsample(3, 3)
self.button_search.config(image=self.small_photo_search, compound=tk.LEFT, style="TButton")
self.button_search.grid(row=0, column=2, columnspan=1, sticky='nw', padx=5)
self.button_search.bind('<Return>')
self.listbox = tk.Listbox(self.frame_content, height=30, width=30)
self.listbox.grid(row=1, column=0, padx=5)
self.scrollbar = ttk.Scrollbar(self.frame_content, orient=tk.VERTICAL, command=self.listbox.yview)
self.scrollbar.grid(row=1, column=1, sticky='nsw')
self.listbox.config(yscrollcommand=self.scrollbar.set)
self.listbox.bind('<<ListboxSelect>>', self.enter_meaning)
self.textbox = tk.Text(self.frame_content, relief=tk.GROOVE, width=60, height=30, borderwidth=2)
self.textbox.config(wrap='word')
self.textbox.grid(row=1, column=2, sticky='w', padx=5)
# SQLite
self.db = sqlite.connect(r'C:\EsperantoDict\test.db')
self.cur = self.db.cursor()
self.cur.execute("SELECT Esperanto FROM Words ORDER BY Esperanto")
for row in self.cur:
self.listbox.insert(tk.END, row)
self.update_list()
def update_list(self):
self.listbox.delete(0, tk.END)
search_term = self.search_var.get().lower()
if search_term == 'type to search':
search_term = ''
self.cur.execute("SELECT Esperanto FROM Words WHERE LOWER(Esperanto) LIKE ? ORDER BY Esperanto",
('%' + search_term + '%',))
for row in self.cur:
item = row[0]
self.listbox.insert(tk.END, item)
for row in range(0, self.listbox.size(), 2):
self.listbox.itemconfigure(row, background="#f0f0ff")
def edit_input(self, tag):
word_to_esp = {'gx': 'ĝ', 'cx': 'ĉ', 'hx': 'ĥ', 'jx': 'ĵ', 'ux': 'ŭ', 'sx': 'ŝ'}
user_input = self.entry_search.get()
user_input = user_input.lower()
for i in word_to_esp:
if user_input.__contains__(i):
a = user_input.replace(i, word_to_esp[i])
return self.search_var.set(a)
def enter_meaning(self, tag=None):
index = self.listbox.curselection()
esperanto = self.listbox.get(index)
results = self.cur.execute("SELECT English FROM Words WHERE Esperanto = ?", (esperanto,))
for row in results:
self.textbox.delete(1.0, tk.END)
self.textbox.insert(tk.END, row[0])
def entry_delete(self, tag):
if self.entry_search.get():
self.entry_search.delete(0, tk.END)
self.textbox.delete(1.0, tk.END)
return None
def entry_insert(self, tag):
if self.entry_search.get() == '':
self.entry_search.insert(0, "Type to Search")
return None
def main():
root = tk.Tk()
EsperantoDict(root)
root.mainloop()
if __name__ == '__main__': main()
# db tbl name: Words
# db first field name: Esperanto
# db second field name: English

How to fetch one row and display it on textbox and increment it automatically

i wrote this python 3 program, i want to for each row in field Esperanto, get it's corresponding row in the other field in database named English. for example: when i click on row 1 in listbox, i want the text of the row 1 in English field of my db to be displayed on the textbox. now it fetches all the rows and it's a disaster, how can i do that? thanks.
#! /usr/bin/env python3
#GeologyDict by Ali M
import sqlite3 as sqlite
import tkinter as tk
from tkinter import Text
from tkinter import Entry
from tkinter import Scrollbar
from tkinter import ttk
#GUI Widgets
class EsperantoDict:
def __init__(self, master):
master.title("EsperantoDict")
master.resizable(False, False)
master.configure(background='#EAFFCD')
self.style = ttk.Style()
self.style.configure("TFrame", background='#EAFFCD')
self.style.configure("TButton", background='#EAFFCD')
self.style.configure("TLabel", background='#EAFFCD')
self.frame_header = ttk.Frame(master, relief=tk.FLAT)
self.frame_header.pack(side=tk.TOP, padx=5, pady=5)
self.logo = tk.PhotoImage(file=r'C:\EsperantoDict\eo.png')
self.small_logo = self.logo.subsample(10, 10)
ttk.Label(self.frame_header, image=self.small_logo).grid(row=0, column=0, stick="ne", padx=5, pady=5, rowspan=2)
ttk.Label(self.frame_header, text='EsperantoDict', font=('Arial', 18, 'bold')).grid(row=0, column=1)
self.frame_content = ttk.Frame(master)
self.frame_content.pack()
self.entry_search = ttk.Entry(self.frame_content)
self.entry_search.grid(row=0, column=0)
self.entry_search.insert(tk.END, "Type to Search")
self.entry_search.bind('<Button-1>', self.entry_delete)
self.button_search = ttk.Button(self.frame_content, text="Search")
self.aks = tk.PhotoImage(file=r'C:\EsperantoDict\search.png')
self.small_aks = self.aks.subsample(3, 3)
self.button_search.config(image=self.small_aks, compound=tk.LEFT)
self.button_search.grid(row=0, column=1, columnspan=2)
self.listbox = tk.Listbox(self.frame_content, height=28)
self.listbox.grid(row=1, column=0)
self.scrollbar = ttk.Scrollbar(self.frame_content, orient=tk.VERTICAL, command=self.listbox.yview)
self.scrollbar.grid(row=1, column=1, sticky='ns')
self.listbox.config(yscrollcommand=self.scrollbar.set)
self.listbox.bind('<<ListboxSelect>>', self.enter_meaning)
self.textbox = tk.Text(self.frame_content, width=60, height=27)
self.textbox.grid(row=1, column=2)
# SQLite
self.db = sqlite.connect(r'C:\EsperantoDict\test.db')
self.cur = self.db.cursor()
self.cur.execute('SELECT Esperanto FROM Words')
for row in self.cur:
self.listbox.insert(tk.END, row)
# SQLite
def enter_meaning(self, tag):
if self.listbox.curselection():
results = self.cur.execute("SELECT English FROM Words")
for row in results:
self.textbox.insert(tk.END, row)
def entry_delete(self, tag):
self.entry_search.delete(0, tk.END)
return None
def main():
root = tk.Tk()
esperantodict = EsperantoDict(root)
root.mainloop()
if __name__ == '__main__': main()
#db table name: Words
##db first field name: Esperanto
##db second field name: English

Categories

Resources