SHARE
    TWEET
    Hasli4

    Timer Turtle

    Jul 21st, 2025
    580
    0
    Never
    Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
    Python 1.82 KB | None | 0 0
    1. import turtle
    2. import time
    3. screen = turtle.Screen()
    4. screen.title("Секундомер")
    5. elapsed = 0.0
    6. running = False
    7. last_update = 0.0
    8. display = turtle.Turtle()
    9. display.hideturtle()
    10. display.penup()
    11. display.goto(0, 50)
    12. def format_time(t):
    13. h = int(t // 3600)
    14. m = int((t % 3600) // 60)
    15. s = int(t % 60)
    16. return f"{h:02d}:{m:02d}:{s:02d}"
    17. def update_clock():
    18. global elapsed, last_update
    19. if running:
    20. now = time.time()
    21. elapsed += now - last_update
    22. last_update = now
    23. display.clear()
    24. display.write(format_time(elapsed), align="center", font=("Arial", 24, "normal"))
    25. screen.ontimer(update_clock, 100)
    26. def start(x=None, y=None):
    27. global running, last_update
    28. if not running:
    29. running = True
    30. last_update = time.time()
    31. update_clock()
    32. def pause(x=None, y=None):
    33. global running, elapsed
    34. if running:
    35. running = False
    36. display.clear()
    37. display.write(format_time(elapsed), align="center", font=("Arial", 24, "normal"))
    38. def stop(x=None, y=None):
    39. global running, elapsed
    40. running = False
    41. elapsed = 0.0
    42. display.clear()
    43. display.write(format_time(elapsed), align="center", font=("Arial", 24, "normal"))
    44. def make_button(label, pos, callback):
    45. btn = turtle.Turtle()
    46. btn.hideturtle()
    47. btn.penup()
    48. btn.shape("square")
    49. btn.shapesize(stretch_wid=1, stretch_len=4)
    50. btn.fillcolor("lightgray")
    51. btn.goto(pos)
    52. btn.showturtle()
    53. btn.write(label, align="center", font=("Arial", 12, "normal"))
    54. btn.onclick(callback)
    55. return btn
    56. make_button("START", (-100, -50), start)
    57. make_button("PAUSE", (0, -50), pause)
    58. make_button("STOP", (100, -50), stop)
    59. display.write("00:00:00", align="center", font=("Arial", 24, "normal"))
    60. screen.mainloop()
    Advertisement
    Add Comment
    Please, Sign In to add comment
    Public Pastes
    We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
    Not a member of Pastebin yet?
    Sign Up, it unlocks many cool features!

    AltStyle によって変換されたページ (->オリジナル) /