最近在做一个复选框删除的模块
# 删除
def delButtonClicked(self):
try:
conn = sqlite3.connect('../db/sample.db')
cur = conn.cursor()
data = cur.fetchall()
vol = len(data[0])
row = len(data)
row_box_list = []
for i in range(row):
if self.tableWidget.cellWidget(i, vol - 7).isChecked() is True:
reply = QMessageBox.information(self, '确认', '确定删除数据?', QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if reply == QMessageBox.Yes:
row_box_list.append(i)
row_box_list.reverse() # 将数据进行降序
for j in row_box_list:
self.tableWidget.removeRow(j) # 删除选中行数据
else:
print(QMessageBox.information(self, "提醒", "请选择要删除的数据", QMessageBox.Yes, QMessageBox.Yes))
except Exception as e:
print('异常', e)
报错:list index out of range