Sequentially timed events using Python/Tkinter - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: General (https://python-forum.io/forum-1.html) +--- Forum: News and Discussions (https://python-forum.io/forum-31.html) +--- Thread: Sequentially timed events using Python/Tkinter (/thread-12779.html) |
Sequentially timed events using Python/Tkinter - eabs86 - Sep-12-2018 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! RE: Sequentially timed events using Python/Tkinter - Larz60+ - Sep-12-2018 see Tkinter after event. Example: from post: https://python-forum.io/Thread-Timer-gui?pid=31415#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() RE: Sequentially timed events using Python/Tkinter - eabs86 - Sep-12-2018 Thank you very much! |