'I want to get a date from a Tk.entry
I have tried to use many variables and adding datetime.date but it doesn't work, I will leave my code so that anybody can make it work. I tried to get the numbers from fetch and then used datetime.date but it says that I need to declare the year or something like that. I need that thing to be a date to put it in the SQL database.
fecha = tk.Entry(vent1)
fecha.place(x=80, y=5, width=170, height=30)
fechaL = tk.Label(vent1, text="FECHA")
fechaL.place(x=10, y=7)
nombre=tk.Entry(vent1)
nombre.place(x=80,y=40,width=170,height=30)
nom=tk.Label(vent1,text="nombre")
nom.place(x=10,y=45,)
rubro=tk.Entry(vent1)
rubro.place(x=80, y=80, width=170, height=30)
rubroL = tk.Label(vent1,text='rubro')
rubroL.place(x=10, y=86)
precio=tk.Entry(vent1)
precio.place(x=80, y=120, width=170, height=30)
precioL=tk.Label(vent1,text="precio")
precioL.place(x=10, y=126)
# guardar funcion
fechad=fecha.get()
fechad = datetime.datetime(day,month,year)
nombred = nombre.get()
rubrod = rubro.get()
preciod = precio.get()
conn = sql3.connect('costos.db')
cursor = conn.cursor()
# cursor.execute("""CREATE TABLE COSTOS(fecha integer,nombre text,rubro text,costo integer)""")
def guardar():
cursor.execute("INSERT INTO COSTOS VALUES(:fecha,:nombre,:rubro,:costo)",{"fecha":fechad, "nombre":nombred,"rubro":rubrod,"costo":preciod})
cursor.execute("SELECT*FROM COSTOS WHERE fecha='25/7/2021'")
print(cursor.fetchall())
conn.commit()
conn.close()
save=tk.Button(vent1, text="guardar",command=guardar)
save.place(x=260, y=69)
app.mainloop()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
