Python Forum
Sequentially timed events using Python/Tkinter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sequentially timed events using Python/Tkinter
#1
I need to develop a simple interface for Stroop test using Python, but I don't know how to start it.

The interface would be like:

10 seconds in a blank screen, the 10 seconds with a colored word on the center of the screen. This would repeat like 10 times, then finish the application.

The problem is: I don't know if I have to use Tkinter + anothe lib (timed events), or if Tkinter provides the methods to use timed events.

Could anyone enlight me,please?

Thank you very much!
Reply
#2
see Tkinter after event.
Example:
from post: https://python-forum.io/Thread-Timer-gui...5#pid31415

name: 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]
Usage Example:
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()
Reply
#3
Thank you very much!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  looking for code to do timed prompt on terminal Skaperen 1 1,076 Jul-10-2022, 05:40 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020