我有一个tkinter应用程序,首先有一个login/signin页面(signin将一个新用户插入到数据库中,并正常工作),还有一个主页面,其中有一个包含元素的表和一个按钮,用于使用此函数删除元素:
def delete(self):
with sqlite3.connect(env['DB']) as conn:
selected = self.AuthTable.Table.item(self.AuthTable.Table.selection()[0])
curr = conn.cursor()
curr.execute("DELETE FROM 'Authentifiants' WHERE authId=?", (selected['tags'][0],))
conn.commit()
self.AuthTable.search()
但它不起作用,并引发:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.2288.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "F:\Acces Rapide\Desktop\Tech\d3v\WorkSpace\Projects\SecurityTemp\.venv\lib\site-packages\customtkinter\windows\widgets\ctk_button.py", line 527, in _clicked
self._command()
File "f:\Acces Rapide\Desktop\Tech\d3v\WorkSpace\Projects\SecurityTemp\src\app\authentifiants.py", line 90, in <lambda>
command=lambda: self.delete(),
File "f:\Acces Rapide\Desktop\Tech\d3v\WorkSpace\Projects\SecurityTemp\src\app\authentifiants.py", line 104, in delete
conn.commit()
sqlite3.OperationalError: database is locked
我认为这是因为我没有关闭conn,所以我将它们更改为with
语句,但情况相同
下面是github项目:https://github.com/jl-houss/Security
1条答案
按热度按时间czfnxgou1#
我解决了,问题是
with sqlite3.connect()
没有关闭连接,所以数据库被锁定