У меня есть система паролей, которая хранит пароль для программы python в таблице SQL. Я хочу, чтобы пользователь мог изменить пароль в окне tkinter, но я не уверен, как использовать значение переменной python в качестве значения для таблицы SQL. Вот пример кода:Вставить значение переменной python в таблицу SQL
import tkinter
from tkinter import *
import sqlite3
conn = sqlite3.connect('testDataBase')
c = conn.cursor()
c.execute("INSERT INTO info Values('test')")
c.execute("SELECT password FROM info")
password = (c.fetchone()[0])
#Window setup
admin = tkinter.Tk()
admin.minsize(width=800, height = 600)
admin.maxsize(width=800, height = 600)
#GUI
passwordChangeLabel = Label(admin, text="It is recommended to change your password after first login!", font=("Arial", 14))
passwordChangeLabel.pack()
passwordChangeCurrentPasswordLabel = Label(admin, text="Current Password: ", font=("Arial", 11))
passwordChangeCurrentPasswordLabel.place(x=275, y=30)
passwordChangeCurrentPasswordEntry = Entry(admin)
passwordChangeCurrentPasswordEntry.place(x=405, y=32.5)
passwordChangeNewPasswordLabel = Label(admin, text="New Password: ", font=("Arial", 11))
passwordChangeNewPasswordLabel.place(x=295, y=50)
passwordChangeNewPasswordEntry = Entry(admin)
passwordChangeNewPasswordEntry.place(x=405, y=52.5)
passwordChangeButton = Button(admin, text="Submit", width=20)
passwordChangeButton.place(x=350, y=80)
def changePasswordFunction(event):
newPassword = passwordChangeNewPasswordEntry.get()
enteredPassword = passwordChangeCurrentPasswordEntry.get()
if enteredPassword == password:
c.execute("REPLACE INTO info(password) VALUES(newPassword)")
else:
wrong = tkinter.Toplevel()
wrong.minsize(width=200, height = 100)
wrong.maxsize(width=200, height = 100)
Label(wrong, text="Sorry that password is incorrect!", font=("Arial", 24), anchor=W, wraplength=180, fg="red").pack()
admin.bind('<Return>', changePasswordFunction)
passwordChangeButton.bind('<Button-1>', changePasswordFunction)
Этот код вызовет ошибку:
sqlite3.OperationalError: no such column: newPassword
Как правильно заменить предыдущее значение в столбце пароля с новым введенным паролем?
Вы прочитали документацию по параметризованным запросам? https://docs.python.org/2/library/sqlite3.html –