I want to do an accountant in Tkinter little by little. At the moment I want you to show me the date in seconds (yes, I know it's a bit weird ...) through this function:
def Date_secondsnow():
now = datetime.now()
Datesecondsnow = now.second + now.minute*60 + now.hour*60*60 + now.day*24*60*60 + now.month*30*24*60*60 + now.year*365*24*60*60
return Datesecondsnow
The previous function shows the present date approximately in seconds. The question is to try to appear in a label, that date updated second by second.
Conditions:
- Do it without defining any class (if possible)
I tried to do it by putting this snippet of code at the end of my program:
while True:
Display()
but it does not work for me, the second to second date is not updated (Display () is described below). The "start" and "stop" buttons do the same thing but I do not care at the moment.
The code is as follows:
import tkinter as tk
from tkinter import *
from random import randint
from datetime import datetime, date, time, timedelta
#DECLARACIÓN DE FUNCIONES
def Date_secondsnow():
now = datetime.now()
Datesecondsnow = now.second + now.minute*60 + now.hour*60*60 + now.day*24*60*60 + now.month*30*24*60*60 + now.year*365*24*60*60
return Datesecondsnow
def starcounter():
labelQuestion = tk.Label(frame, text=str(Date_secondsnow()), padx=10 )
labelQuestion.grid(row=0, column=0, sticky=tk.W)
def Display():
labelQuestion = tk.Label(frame, text=str(Date_secondsnow()), padx=10 )
labelQuestion.grid(row=0, column=0, sticky=tk.W)
#Creando una ventanta principal
window=tk.Tk()
window.geometry("500x300+100+100")
window.title("Cronómetro")
#Creamos un frame como contenedor
frame = tk.Frame(window)
#Creando un label para mostrar la cuenta
#labelQuestion = tk.Label(frame, text="Cuenta", padx=10 )
#labelQuestion.grid(row=0, column=0, sticky=tk.W)
labelQuestion = tk.Label(frame, text=str(Date_secondsnow()), padx=10 )
labelQuestion.grid(row=0, column=0, sticky=tk.W)
#Definimos un tamaño mínimo de la fila central delgrid para que quede un espacio entre cada entry y posicionamos el frame
frame.grid_rowconfigure(1, minsize=10)
frame.place(x=0,y=140)
#Creando un botón para Iniciar
btnSave=tk.Button(window,text="Iniciar",command=starcounter,font=("Agency FB",14))
btnSave.place(x=130,y=210)
#Creando un botón para Parar
btnStop=tk.Button(window,text="Parar",command=starcounter,font=("Agency FB",14))
btnStop.place(x=190,y=210)
#Iniciamos el mailoop
window.mainloop()
#App = Display(master=root)
Thank you very much in advance.