Я свободен sh пользователь Python
, и я работал на Tkinter
и Sqlite3
. Я сделал базу данных с кнопками Добавить и Удалить. Для функции удаления, когда я вызываю row index 0
, отображается []
, однако, когда я проверяю в браузере БД приложение SQL, строка заполнена. Я попытался row index 0 to 1
в качестве номера индекса, и оба []
. но index number 2
принимает index number 0
, когда я нажимаю на записи шоу. Возможно, я что-то упустил при звонке record_ID = Delete_entry.get()
def delete():
# Connect Database
conn = sqlite3.connect("sample.db")
# Create cursor
c = conn.cursor()
c.execute("DELETE FROM sample WHERE oid="+ Delete_entry.get())
#Create commit
conn.commit()
#Clear textboxes
name_entry_delete.delete(0, END)
lastname_entry_delete.delete(0, END)
TC_entry_delete.delete(0, END)
#Close DB
conn.close()
Delete_win.destroy()
def delete_editwin():
global name_entry_delete
global lastname_entry_delete
global TC_entry_delete
global Delete_win
global Delete_entry
Delete_win=Tk()
Delete_win.title("Delete record")
Delete_win.geometry("450x200")
name_entry_delete = Entry(Delete_win)
name_lbl = Label(Delete_win, text="Name: ", font=("Arial", "12"))
name_entry_delete.grid(row=0, column=1, padx=10, ipadx=50, pady=5)
name_lbl.grid(row=0, column=0, pady=5)
lastname_entry_delete = Entry(Delete_win)
lastname_lbl = Label(Delete_win, text="LastName: ", font=("Arial", "12"))
lastname_entry_delete.grid(row=1, column=1, padx=10, ipadx=50, pady=5)
lastname_lbl.grid(row=1, column=0, pady=5)
TC_entry_delete = Entry(Delete_win)
TC_lbl = Label(Delete_win, text="TC no: ", font=("Arial", "12"))
TC_entry_delete.grid(row=2, column=1, padx=10, ipadx=50, pady=5)
TC_lbl.grid(row=2, column=0, pady=5)
Delete_button = Button(Delete_win, text="Delete record",command=delete)
Delete_button.grid(row=4, column=0)
Delete_entry = Entry(Delete_win)
Delete_entry.grid(row=3, column=1)
#conn = sqlite3.connect("sample.db")
#cur = conn.cursor()
#cur.execute("SELECT * FROM sample")
#rows = cur.fetchall()
#for row in rows:
#print(row)
def show():
record_ID = Delete_entry.get()
print(record_ID)
# Connect Database
conn = sqlite3.connect("sample.db")
# Create cursor
c = conn.cursor()
c.execute("SELECT * FROM sample WHERE oid=" + record_ID)
records = c.fetchall()
print(records)
for record in records:
name_entry_delete.insert(0, record[0])
lastname_entry_delete.insert(0, record[1])
TC_entry_delete.insert(0, record[2])
show_btn = Button(Delete_win, text="Show Records", command=show, state=DISABLED)
show_btn.grid(row=3, column=0)
# Create commit
conn.commit()
# Close DB
conn.close()
show_btn = Button(Delete_win, text="Show Records", command=show)
show_btn.grid(row=3, column=0)