【发布时间】:2018-03-08 23:48:47
【问题描述】:
我需要从一列中提取一个数字
cursor.execute('''SELECT vacas FROM animales''')
cantidad1 = cursor.fetchone()
然后我需要在 Tkinter 标签中显示这个数字:
cantidad = Label (ventana, textvariable=cantidad1).grid(row=1, column=3)
我有一个刷新按钮来更新数据。
ref = Button (ventana, text="Refresh", command=update )
问题是标签总是空白,即使我按下按钮并调用 Update():
完整代码如下:
cantidad1 = 0
ventana = Tk()
cursor = db.cursor()
def update():
cursor.execute('''SELECT vacas FROM animales''')
cantidad1 = cursor.fetchone()
print (cantidad1[0]) #The number shown in command is right, but blank in tkinter.
ref = Button (ventana, text="Refresh", command=update )
ref.grid(row=3, column=2)
cantidad = Label (ventana, textvariable=cantidad1).grid(row=1, column=3)
ventana.mainloop()
https://imgur.com/AvsNAuL "截图 tkinter 空白"
【问题讨论】: