[英]Tkinter 'Entry' object is not callable
I am getting error with a button that I created.我创建的按钮出错。 My code is this:我的代码是这样的:
#!/usr/bin/python
from tkinter import *
root = Tk()
root.resizable(width=FALSE, height=FALSE)
#funcion para agregar datos nuevos
def agregarDato(fecha,campo,labor,tipoGasto,monto,loggedBy,detalle):
dato=[fecha,campo,labor,tipoGasto,monto,loggedBy,detalle]
mesAno=fecha.split('/')[1]+'-'+fecha.split('/')[2]
#si el archivo mes-ano existe entonces se edita. Si no, se crea y agrega
archivo=open(mesAno+'.txt', 'a')
archivo.write(str(dato)+'\n')
leftFrame=Frame(root, width=500,height=300)
leftFrame.pack(side=LEFT)
rightFrame=Frame(root, width=500,height=300)
rightFrame.pack()
### Texto y cajas
label_fecha=Label(leftFrame,text='Fecha:')
label_campo=Label(leftFrame,text='Campo:')
label_labor=Label(leftFrame,text='Labor:')
label_tipoGasto=Label(rightFrame,text='Tipo de gasto:')
label_monto=Label(rightFrame,text='Monto:')
label_detalle=Label(rightFrame,text='Detalle:')
label_loggedBy=Label(leftFrame,text='Autor:')
entry_fecha=Entry(leftFrame)
entry_campo=Entry(leftFrame)
entry_labor=Entry(leftFrame)
entry_tipoGasto=Entry(rightFrame)
entry_monto=Entry(rightFrame)
entry_detalle=Entry(rightFrame)
entry_loggedBy=Entry(leftFrame)
label_fecha.grid(row=0,column=0,sticky=E)
label_campo.grid(row=1,column=0,sticky=E)
label_labor.grid(row=2,column=0,sticky=E)
label_tipoGasto.grid(row=0,column=0,sticky=E)
label_monto.grid(row=1,column=0,sticky=E)
label_detalle.grid(row=2,column=0,sticky=E)
label_loggedBy.grid(row=3,column=0,sticky=E)
entry_fecha.grid(row=0,column=1)
entry_campo.grid(row=1,column=1)
entry_labor.grid(row=2,column=1)
entry_tipoGasto.grid(row=0,column=1)
entry_monto.grid(row=1,column=1)
entry_detalle.grid(row=2,column=1)
entry_loggedBy.grid(row=3,column=1)
###botones ingresar y volver
boton_ingresar=Button(rightFrame,text='Ingresar',command= lambda: agregarDato(entry_fecha.get(),entry_campo.get,entry_labor.get(),entry_tipoGasto(),entry_monto.get(),entry_loggedBy.get(),entry_detalle.get()))
boton_ingresar.grid(row=3,column=0)
root.mainloop()
The error that I get is:我得到的错误是:
Traceback (most recent call last):
File "C:\Python34\lib\tkinter\__init__.py", line 1487, in __call__
return self.func(*args)
File "C:\Users\Matias\Desktop\Proyecto MiPi\Int_pagAgregarDato.py", line 56, in <lambda>
boton_ingresar=Button(rightFrame,text='Ingresar',command= lambda: agregarDato(entry_fecha.get(),entry_campo.get(),entry_labor.get(),entry_tipoGasto(),entry_monto.get(),entry_loggedBy.get(),entry_detalle.get()))
TypeError: 'Entry' object is not callable
In the line that is identified by the error code, you have this:在由错误代码标识的行中,您有:
boton_ingresar=Button(..., entry_tipoGasto(),...)
Notice how you are trying to call the entry (as the error message states), rather than calling the get
method on the entry.请注意您如何尝试调用条目(如错误消息所述),而不是调用条目上的get
方法。
Change the code to be ...entry_tipoGastro.get()...
将代码更改为...entry_tipoGastro.get()...
In the constructor of your button you put:在按钮的构造函数中,您放置:
entry_tipoGasto()
instead of代替
entry_tipoGasto.get()
so you try to call an entry所以你尝试调用一个条目
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.