Python Forum

Full Version: Timer gui
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, i'm new in python. I'm doing some image processing using cv2.

I've already set up the chroma and everything, but now i want to add some interface that shows a timer and every 20 seconds it takes a picture and change the backgroud.

I really don't know how to start with the interface, and any suggestion with the timer? what's the best option?

Thank you.
Here's a simple event timer:
from EventTimer import *

def function1():
    print('Function 1 triggered')

def function2():
    print('Function 2 triggered')

def function3():
    print('Function 2 triggered')

def finalone():
    print('Final function triggered')

def launch():
    e = EventTimer()
    e.addEvent(function1, seconds=5)
    e.addEvent(function2, seconds=10)
    e.addEvent(function3, seconds=20)
    e.addEvent(finalone, seconds=25)
    e.startAll()
    print("This statement shows that you can do other things while")
    print('Waiting for events to trigger')
    print('And then wait for all to finish')
    print('Events will still trigger even if other processes are running')
    print('Only call waitForFinish when you are ready to do so')
    e.waitForFinish()

if __name__ == '__main__':
    launch()
you also need EventTimer.py
import threading


class EventTimer:
    '''
    Creates overlaping threaded timed events
    Events can be set to trigger in days, hours, minutes, and/or seconds
    Any number of events can be created, and are treated independently, thus can
    overlap each other.
    Program execution will continue until all events have completed.
    the function that is passed to each timer will execute after the timeout has
    been reached
    '''

    def __init__(self):
        self.threadList =

    def addEvent(self, func, days=0, hours=0, minutes=0, seconds=0):
        times = [days, hours, minutes, seconds]
        multiplier = [86400, 3600, 60, 1]
        count = 0

        for n in range(len(times)):
            count += times[n] * multiplier[n]

        t = threading.Timer(count, func)
        self.threadList.append(t)

    def startAll(self):
        # Start threads
        [th.start() for th in self.threadList]

    def waitForFinish(self):
        # wait for all to finish
        [th.join() for th in self.threadList]
This is old code, I wrote when relatively new to Python, but I just tried it and it works
Style may be rather crude.