我想从 ListBox 中的选定内容中删除数据。我尝试了一切,但它不起作用。我试过简单的文件。有效。我在这里写了相同的代码,但它不起作用。我被困两天了。请帮忙。
from tkinter import *
import sqlite3
from tkinter import messagebox
import randevuEkleme as fRE
from tkcalendar import *
def randevularFormunuAc():
root = Tk()
root.title("Randevu Listesi Formu")
root.geometry("750x500")
randevuListesi = Listbox(root, width=50, bg="yellow", selectmode=SINGLE)
takvim = Calendar(root, selectmode="day", year=2020, month=5, day=22)
takvim.grid(row=0, column=0)
randevuListesi.grid(row=1, column=0)
secilen = randevuListesi.curselection()
def randevulariListele(): #OK!
con = sqlite3.connect('veri2.db')
c = con.cursor()
c.execute("SELECT * FROM randevular")
liste = c.fetchall()
con.commit()
con.close()
randevuListesi.delete(first=0,last=END)
for i in liste:
randevuListesi.insert(END,i)
con = sqlite3.connect('veri2.db')
c = con.cursor()
c.execute("SELECT * FROM randevular")
liste = c.fetchall()
con.commit()
con.close()
for i in liste:
randevuListesi.insert(END, i)
def randevuSil():
con = sqlite3.connect('veri2.db')
c = con.cursor()
# Problem is HERE!!!
c.execute("DELETE FROM randevular WHERE rowid = (?)", (secilen[0] + 1,))
# PROBLEMIS HERE!!!
con.commit()
con.close()
btnListele = Button(root, text="Randevuları Listele",command=randevulariListele)
btnRandevuEkle = Button(root,text="Randevu Ekle",command=fRE.randevuEklemeFormunuAc)
btnRandevuSil = Button(root,text="Randevuyu Sil",command=randevuSil()) !!!!
btnCikis = Button(root, text="Geri", command=root.quit)
btnListele.grid(row=2,column=0)
btnRandevuEkle.grid(row=2,column=1)
btnRandevuSil.grid(row=2,column=2)
btnCikis.grid(row=2,column=3)
root.mainloop()
错误信息是:
File "C:\Users\kutla\PycharmProjects\fizyoOta1.0\randevularFormu.py", line 43, in randevuSil
c.execute("DELETE FROM randevular WHERE rowid = (?)", (secilen[0] + 1,))
IndexError: tuple index out of range