python - 如何在我的 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")
解决方案
推荐阅读
- java - Pircbotx 通道 setMode() 在 main() 方法中不起作用
- excel - 需要在 excel 中使用动态范围的特定集群的 unqiue VM 总数
- java - 如何使用 mapstructs 中的列表将列表映射到对象
- google-sheets - 将表格公式调整 +1 行 -- A 列中的 ('SheetX'!$A3) --> B 列中的 ('SheetX'!$A4)
- c - 将数组的大小定义为用户合法输入的变量吗?
- javascript - 尝试更改图表画布的高度和宽度
- java - 如何在 Eclipse Juno 中添加 Junit 5 库?
- c++ - 将给定类型的任何枚举作为函数参数传递
- python-3.x - 如何使用 numpy.random.uniform 生成 int16 类型的随机数?
- apache - 如何在 Apache 中设置 HTTP 替代服务?