E-Dog13
Posts: 1
Joined: Sat Apr 06, 2019 3:31 am

Anniversary present help... Count up timer?

Sat Apr 06, 2019 3:42 am

Hello. I am kind of new to using a Raspberry Pi. I am looking to make an anniversary present for my wife that is a bit different. Since I can't seem to find one pre-made I decided to try to make it instead using a Pi. What I am looking for is help with the best way to go about making this item and help with any coding that it might take to see this come to fruition. I want to make a count up timer. Specifically I would like to be able to input The specific date and time we were married and have the elapsed time since then to be displayed. I was thinking of having a small screen attached to the Pi and have it display the elapsed time in seconds, minutes, hours, days, weeks, and years, or something like that if possible. Any help or suggestions would be greatly appreciated. Thank you.

Andyroo
Posts: 2827
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Anniversary present help... Count up timer?

Sat Apr 06, 2019 2:53 pm

Sweet.

You could make an electronic picture frame and show pictures of you two (and any family of course) at the same time.

Python is reasonably easy to learn (esp. if you have a good reason) and is good at handling dates / time - have a look through https://www.guru99.com/date-time-and-da ... ython.html for some examples.

Screens range in size from very small up to monitor sized mirrors. Personally, I would go for something like the Foundations own screen and build it as a picture frame with the time overlaid on the picture in years/months/days.

You could make it ‘magic’ by using a movement sensor or button BUT the more complex it is the dealer you get and can loose the original aim (not that I EVER do that :roll: :oops: )
Need Pi spray - these things are breeding in my house...

User avatar
DougieLawson
Posts: 35119
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Anniversary present help... Count up timer?

Sat Apr 06, 2019 7:29 pm

This is not fully tested but it works for me for today

Code: Select all

#!/usr/bin/python3

import tkinter
import datetime
from datetime import date

class DaysSince(tkinter.Tk):

    def __init__(self, rootWindow):
    
        self.startYear = 1986
        self.startMonth = 6
        self.startDay = 7
        self.startHour = 15
        self.startMin = 0
        
        self.rootWindow = rootWindow
        self.years = tkinter.Label(self.rootWindow, font = ('fixed', 20),)
        self.yearsT = tkinter.Label(self.rootWindow, font = ('fixed', 20),)
        self.months = tkinter.Label(self.rootWindow, font = ('fixed', 20),)
        self.monthsT = tkinter.Label(self.rootWindow, font = ('fixed', 20),)
        self.days = tkinter.Label(self.rootWindow, font = ('fixed', 20),)
        self.daysT = tkinter.Label(self.rootWindow, font = ('fixed', 20),)
        self.hours = tkinter.Label(self.rootWindow, font = ('fixed', 20),)
        self.hoursT = tkinter.Label(self.rootWindow, font = ('fixed', 20),)
        self.mins = tkinter.Label(self.rootWindow, font = ('fixed', 20),)
        self.minsT = tkinter.Label(self.rootWindow, font = ('fixed', 20),)
        self.Grid()
        self.Labels()
        self.tick()

    def Grid(self):
        self.years.grid(sticky = 'N', row = 1, column = 2, padx = 5, pady = (20,20))
        self.months.grid(sticky = 'N', row = 2, column = 2, padx = 5, pady = (20,20))
        self.days.grid(sticky = 'N', row = 3, column = 2, padx = 5, pady = (20,20))
        self.hours.grid(sticky = 'N', row = 4, column = 2, padx = 5, pady = (20,20))
        self.mins.grid(sticky = 'N', row = 5, column = 2, padx = 5, pady = (20,20))
        self.yearsT.grid(sticky = 'N', row = 1, column = 1, padx = 5, pady = (20,20))
        self.monthsT.grid(sticky = 'N', row = 2, column = 1, padx = 5, pady = (20,20))
        self.daysT.grid(sticky = 'N', row = 3, column = 1, padx = 5, pady = (20,20))
        self.hoursT.grid(sticky = 'N', row = 4, column = 1, padx = 5, pady = (20,20))
        self.minsT.grid(sticky = 'N', row = 5, column = 1, padx = 5, pady = (20,20))

    def Labels(self):
        self.rootWindow.title('Days since ')
        self. yearsT.config(text="Years:  ")
        self.monthsT.config(text="Months: ")
        self.daysT.config(text="Days:   ")
        self.hoursT.config(text="Hours:  ")
        self.minsT.config(text="Minutes:")
        self.rootWindow.configure(background="green")

    def tick(self):
        now = datetime.datetime.now()
        print (now.min, now.minute)
        self.doCalculation(now.year, now.month, now.day, now.hour, now.minute)
        self.mins.after(2000,self.tick)

    def doCalculation(self, nowYR, nowMTH, nowDAY, nowHOUR, nowMIN):
        daysOffset = 31
        if nowMTH == 2:
            daysOffset = 28
            if (nowYR % 4 == 0):
                daysOffset = 29
            if (nowYR % 100 == 0):
                daysOffset = 28
            if (nowYR % 400 == 0):
                daysOffset = 29
        if (nowMTH == 9 or nowMTH == 4 or nowMTH == 6 or nowMTH == 11):
            daysOffset = 30

        hourSince = nowHOUR - self.startHour
        minSince = nowMIN - self.startMin
        daySince = nowDAY - self.startDay
        monthSince = nowMTH - self.startMonth
        yearSince = nowYR - self.startYear
        print ("Before", hourSince, minSince, daySince, monthSince, yearSince)
        if minSince < 0:
            minSince = 60 + minSince
            hourSince -= 1
        if hourSince < 0:
            hourSince = 24 + hourSince
            daySince -= 1
        if daySince < 0:
            monthSince -= 1
            daySince = daysOffset + daySince
        if monthSince < 0:
            monthSince = 12 + monthSince
            yearSince -= 1
        print ("After", hourSince, minSince, daySince, monthSince, yearSince)
        self.years.config(text=yearSince,background="green")
        self.months.config(text=monthSince,background="green")
        self.days.config(text=daySince,background="green")
        self.hours.config(text=hourSince,background="green")
        self.mins.config(text=minSince,background="green")

if __name__ == "__main__":

    root = tkinter.Tk()
    ticker = DaysSince(root)
    root.mainloop()

Note: Having anything remotely humorous in your signature is completely banned on this forum.

Any DMs sent on Twitter will be answered next month.

This is a hippy & doctor free zone.

Return to “Other projects”