【发布时间】:2018-03-09 15:26:06
【问题描述】:
我需要对取自
的变量进行数学运算
a: 一个数据库
b: tkinter 入口
#Get database number
cantidad = IntVar()
cursor.execute('''SELECT terneros FROM animales''')
cantidad.set(cursor.fetchone())
然后,一个 tkinter 条目:
ent_peso = Entry (ventana1, textvariable=peso).grid(row=3, column=2)
当我尝试进行以下操作时
total = StringVar()
total.set(peso*cantidad.get())
messagebox.showinfo("Resultado", "$: "+ total.get())
我明白了
TypeError: getdouble() argument must be str, not tuple
完整代码:
peso = IntVar()
def calcular():
cantidad = IntVar()
cursor.execute('''SELECT terneros FROM animales''')
cantidad.set(cursor.fetchone())
total = StringVar()
total.set(peso.get()*cantidad.get())
messagebox.showinfo("Resultado", "$: "+ total.get())
ent_peso = Entry (ventana, textvariable=peso).grid(row=3, column=2)
but_calc = Button(ventana, text="Calcular", command=calcular).place(x=150,y=115)
ventana.mainloop()
【问题讨论】:
-
转换成字符串
-
@ADWAN “它”是什么意思?
-
没有您提供的代码片段足以重现您遇到的错误。
标签: python database sqlite tkinter