python-3.x - Tkinter 按钮自动点击
问题描述
我正在尝试编写一个自动生成按钮的简单应用程序,并通过单击生成的按钮将它们的值保存到数据库表中。出于某种原因,我不明白在生成按钮时好像它们会自动单击保存所有值。谁能告诉我为什么?
try:
conexion=sqlite3.connect('libreria.db')
cursor=conexion.cursor()
cursor.execute("SELECT * FROM categoria")
cate=cursor.fetchall()
except sqlite3.OperationalError:
print("Error: No hay datos que mostrar")
else:
eleccion=lambda x: cursor.execute("INSERT INTO pedido VALUES(null,{})".format(x))
for c in cate:
print("\n*",c[1],"*")
ttk.Label(marcoprincipal,text="*{}*".format(c[1])).pack(fill="both",expand=1)
libros=cursor.execute("SELECT * FROM libro WHERE categoria_id={}".format(c[0])).fetchall()
for l in libros:
print("\t",l[1])
ttk.Button(marcoprincipal,text="{}".format(l[1]),command=eleccion(l[0])).pack()
conexion.commit()
conexion.commit()
conexion.close()
解决方案
推荐阅读
- c++ - 是否允许在 decltyped 的变量的初始化程序中使用 decltype?
- javascript - 收听元数据 Firestore
- jquery - 如何将数据从我的 Ajax 函数传递到局部视图中的 HTML 模型?
- arrays - 如何使用数组将范围加入格式化字符串
- r - R中用于捕获名称和段落的正则表达式
- angular - VSCode 无法识别的单元测试的 Angular 类型定义
- python - tkinter 应用程序使用 MVC 旋转 2 个窗口
- pic - CAN MCP2515 - 环回模式通过 CAN 总线发送消息?
- sql - 在 SQL/PSQL 中更新语句
- r - R函数read.csv在第一个标题名称中插入ï..