Advertisement
kalpin

timers

Aug 7th, 2020
1,538
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. # Countdown Timer - not guiZero
  2. from time import sleep
  3.  
  4. def decrease():
  5.     global currentTime
  6.     sleep(1)
  7.     currentTime -= 1
  8.  
  9. def displayTime(currentTime):
  10.     mins = currentTime // 60
  11.     secs = currentTime % 60
  12.     if secs < 10:
  13.         secs = '0'+str(secs)
  14.     print(f"{mins}:{secs}")
  15.  
  16. print('Starting')
  17. currentTime = 120
  18. while currentTime >= 0:
  19.     displayTime(currentTime)
  20.     decrease()
  21. print('Game Over')
  22.  
  23. #................................................
  24.  
  25. # Change Button bg colour using .repeat
  26. from guizero import App, PushButton
  27.  
  28. app = App(title="Timers",width="600",height="100",bg="white")
  29.  
  30.  
  31. # Event Handlers
  32. def changeBg():
  33.     if btn_open.bg == 'white':
  34.         btn_open.bg = 'black'
  35.         btn_open.text_color = 'white'
  36.     else:
  37.         btn_open.bg = 'white'
  38.         btn_open.text_color = 'black'
  39.    
  40.  
  41. #  Widgets
  42. btn_open = PushButton(app,align="top", text="Click Me", width="fill")
  43. btn_open.bg = 'white'
  44. btn_open.text_color = 'black'
  45.  
  46. btn_open.repeat(1000,changeBg)
  47.  
  48. # Show the GUI on the screen
  49. app.display()
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement