Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 33 additions & 42 deletions Lib/turtledemo/clock.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: cp1252 -*-
""" turtle-example-suite:

tdemo_clock.py
Expand Down Expand Up @@ -52,62 +51,54 @@ def clockface(radius):
jump(-radius)
rt(6)

def display_date_time():
writer.clear()
now = datetime.now()
writer.home()
writer.forward(distance=65)
writer.write(now.strftime(format="%A"),
align="center", font=("TkFixedFont", 14, "bold"))
writer.back(distance=150)
writer.write(now.strftime(format="%Y/%m/%d"),
align="center", font=("TkFixedFont", 14, "bold"))
writer.forward(distance=85)

def initialize_hand(shape, color):
hand = Turtle()
hand.shape(shape)
hand.color(*color)
hand.resizemode("user")
hand.shapesize(1, 1, 3)
hand.speed(0)
return hand

def setup():
global second_hand, minute_hand, hour_hand, writer
mode("logo")
make_hand_shape("second_hand", 125, 25)
make_hand_shape("minute_hand", 130, 25)
make_hand_shape("minute_hand", 115, 25)
make_hand_shape("hour_hand", 90, 25)
clockface(160)
second_hand = Turtle()
second_hand.shape("second_hand")
second_hand.color("gray20", "gray80")
minute_hand = Turtle()
minute_hand.shape("minute_hand")
minute_hand.color("blue1", "red1")
hour_hand = Turtle()
hour_hand.shape("hour_hand")
hour_hand.color("blue3", "red3")
for hand in second_hand, minute_hand, hour_hand:
hand.resizemode("user")
hand.shapesize(1, 1, 3)
hand.speed(0)

second_hand = initialize_hand("second_hand", ("gray20", "gray80"))
minute_hand = initialize_hand( "minute_hand", ("blue1", "red1"))
hour_hand = initialize_hand( "hour_hand", ("blue3", "red3"))

ht()
writer = Turtle()
#writer.mode("logo")
writer.ht()
writer.pu()
writer.bk(85)

def wochentag(t):
wochentag = ["Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday", "Sunday"]
return wochentag[t.weekday()]

def datum(z):
monat = ["Jan.", "Feb.", "Mar.", "Apr.", "May", "June",
"July", "Aug.", "Sep.", "Oct.", "Nov.", "Dec."]
j = z.year
m = monat[z.month - 1]
t = z.day
return "%s %d %d" % (m, t, j)
display_date_time()

def tick():
t = datetime.today()
sekunde = t.second + t.microsecond*0.000001
minute = t.minute + sekunde/60.0
stunde = t.hour + minute/60.0
now = datetime.now()
sekunde = now.second + now.microsecond * 0.000001
minute = now.minute + sekunde / 60.0
stunde = now.hour + minute / 60.0

try:
tracer(False) # Terminator can occur here
writer.clear()
writer.home()
writer.forward(65)
writer.write(wochentag(t),
align="center", font=("Courier", 14, "bold"))
writer.back(150)
writer.write(datum(t),
align="center", font=("Courier", 14, "bold"))
writer.forward(85)
second_hand.setheading(6*sekunde) # or here
minute_hand.setheading(6*minute)
hour_hand.setheading(30*stunde)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix the canvas not clearing after running turtledemo clock, and improve the
clock example suite