Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Time based loops
#1
Having a hard time figuring out how to make timeloops.

The goal is having a text flicker on screen every even number of seconds (2,4,6 etc..)
This is the code i have so far:
intro = True
        x = time.time()
        while intro:
            y = int(time.time() - x)
            if y % 2 == 0:
               message_to_screen(font2,"Keys",white,(width/4,height/2)) 
            else:
               x = time.time()
               win.blit(background,(0,0))
The problem is that the screen is just freezing when running this.
I tried also setting time.sleep(1) after the loop, not working and even if so it kinda ruins the other code.

* Text is appearing on screen, and blit deletes everything off the screen EXCEPT "Keys".
Help will be much appreciated :)
Reply


Messages In This Thread
Time based loops - by Owenix - Sep-20-2018, 03:34 PM
RE: Time based loops - by nilamo - Sep-20-2018, 03:37 PM
RE: Time based loops - by Owenix - Sep-20-2018, 03:43 PM
RE: Time based loops - by nilamo - Sep-20-2018, 05:25 PM
RE: Time based loops - by Owenix - Sep-20-2018, 05:37 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Why recursive function consumes more of processing time than loops? M83Linux 9 4,295 May-20-2021, 01:52 PM
Last Post: DeaD_EyE
  Update Date based on Time/String stevezemlicka 1 2,046 Jan-08-2021, 06:54 PM
Last Post: Gribouillis
  Split gps files based on time (text splitting) dervast 0 1,901 Nov-09-2020, 09:19 AM
Last Post: dervast
  running 2 loops at the same time julio2000 7 4,601 Mar-21-2020, 05:21 PM
Last Post: ndc85430
  Time based control of phillips hue Kimzer 3 3,481 Dec-22-2017, 07:35 PM
Last Post: Kimzer

Forum Jump:

User Panel Messages

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