首页 > 解决方案 > 如何在我的 SQLite 数据库中保存文本框?

问题描述

我想在我的数据库中保存文本,我不能像以前那样给它一个文本变量,以便将它保存在我的数据库中:这是我的代码


lbl_historial = LabelFrame(frame_historial, text='Historial', font='arial 12 bold')
lbl_historial.place(x=1, y=1, width='830', height='450')

myid=StringVar()

entry_idcard = Entry(lbl_historial, font='arial 12', justify='center', relief='sunken', bd=3, textvariable=myid)
entry_idcard.place(x=90, y=20, width='160', height='30')

text_historial = Text(lbl_historial)
text_historial.place(x=16, y=60, width='790', height='300')

btn_save = Button(lbl_historial, text='SAVE', width='9', height='2',
                                   activebackground='goldenrod',
                                   font='arial 12 bold', fg='white', relief='raised', bd=3, bg='green', command= lambda: [registrar()])
btn_save.place(x=200, y=373)

    def registrar():
      
        conn = sqlite3.connect("historial.db")
        c = conn.cursor()

        text = text_historial.get()
        datos = myid.get()

        if len(myid.get().strip()) == 0:
           messagebox.showerror('¡ERROR!', 'Enter a valid ID')
        else:
           c.execute("INSERT INTO history VALUES(?,?)", (datos, text))
           conn.commit()
           messagebox.showinfo("Registered")

标签: pythonpython-3.xsqlitetkinter

解决方案


推荐阅读