(root)/
Python-3.11.7/
Lib/
turtledemo/
clock.py
       1  #!/usr/bin/env python3
       2  # -*- coding: cp1252 -*-
       3  """       turtle-example-suite:
       4  
       5               tdemo_clock.py
       6  
       7  Enhanced clock-program, showing date
       8  and time
       9    ------------------------------------
      10     Press STOP to exit the program!
      11    ------------------------------------
      12  """
      13  from turtle import *
      14  from datetime import datetime
      15  
      16  def jump(distanz, winkel=0):
      17      penup()
      18      right(winkel)
      19      forward(distanz)
      20      left(winkel)
      21      pendown()
      22  
      23  def hand(laenge, spitze):
      24      fd(laenge*1.15)
      25      rt(90)
      26      fd(spitze/2.0)
      27      lt(120)
      28      fd(spitze)
      29      lt(120)
      30      fd(spitze)
      31      lt(120)
      32      fd(spitze/2.0)
      33  
      34  def make_hand_shape(name, laenge, spitze):
      35      reset()
      36      jump(-laenge*0.15)
      37      begin_poly()
      38      hand(laenge, spitze)
      39      end_poly()
      40      hand_form = get_poly()
      41      register_shape(name, hand_form)
      42  
      43  def clockface(radius):
      44      reset()
      45      pensize(7)
      46      for i in range(60):
      47          jump(radius)
      48          if i % 5 == 0:
      49              fd(25)
      50              jump(-radius-25)
      51          else:
      52              dot(3)
      53              jump(-radius)
      54          rt(6)
      55  
      56  def setup():
      57      global second_hand, minute_hand, hour_hand, writer
      58      mode("logo")
      59      make_hand_shape("second_hand", 125, 25)
      60      make_hand_shape("minute_hand",  130, 25)
      61      make_hand_shape("hour_hand", 90, 25)
      62      clockface(160)
      63      second_hand = Turtle()
      64      second_hand.shape("second_hand")
      65      second_hand.color("gray20", "gray80")
      66      minute_hand = Turtle()
      67      minute_hand.shape("minute_hand")
      68      minute_hand.color("blue1", "red1")
      69      hour_hand = Turtle()
      70      hour_hand.shape("hour_hand")
      71      hour_hand.color("blue3", "red3")
      72      for hand in second_hand, minute_hand, hour_hand:
      73          hand.resizemode("user")
      74          hand.shapesize(1, 1, 3)
      75          hand.speed(0)
      76      ht()
      77      writer = Turtle()
      78      #writer.mode("logo")
      79      writer.ht()
      80      writer.pu()
      81      writer.bk(85)
      82  
      83  def wochentag(t):
      84      wochentag = ["Monday", "Tuesday", "Wednesday",
      85          "Thursday", "Friday", "Saturday", "Sunday"]
      86      return wochentag[t.weekday()]
      87  
      88  def datum(z):
      89      monat = ["Jan.", "Feb.", "Mar.", "Apr.", "May", "June",
      90               "July", "Aug.", "Sep.", "Oct.", "Nov.", "Dec."]
      91      j = z.year
      92      m = monat[z.month - 1]
      93      t = z.day
      94      return "%s %d %d" % (m, t, j)
      95  
      96  def tick():
      97      t = datetime.today()
      98      sekunde = t.second + t.microsecond*0.000001
      99      minute = t.minute + sekunde/60.0
     100      stunde = t.hour + minute/60.0
     101      try:
     102          tracer(False)  # Terminator can occur here
     103          writer.clear()
     104          writer.home()
     105          writer.forward(65)
     106          writer.write(wochentag(t),
     107                       align="center", font=("Courier", 14, "bold"))
     108          writer.back(150)
     109          writer.write(datum(t),
     110                       align="center", font=("Courier", 14, "bold"))
     111          writer.forward(85)
     112          second_hand.setheading(6*sekunde)  # or here
     113          minute_hand.setheading(6*minute)
     114          hour_hand.setheading(30*stunde)
     115          tracer(True)
     116          ontimer(tick, 100)
     117      except Terminator:
     118          pass  # turtledemo user pressed STOP
     119  
     120  def main():
     121      tracer(False)
     122      setup()
     123      tracer(True)
     124      tick()
     125      return "EVENTLOOP"
     126  
     127  if __name__ == "__main__":
     128      mode("logo")
     129      msg = main()
     130      print(msg)
     131      mainloop()