Skip to content

Commit 5e62d9b

Browse files
miss-islingtonterryjreedyWulian233
authored
[3.12] [3.13] gh-123370: Fix the canvas not clearing after running turtledemo.clock (gh-123457) (GH-125653) (#125656)
Rewriting the day and date every tick somehow prevented them from being removed either by clicking STOP or loading another example. The solution is to rewrite them only when they change. (cherry picked from commit c124577) (cherry picked from commit 30d7e9e) Co-authored-by: Terry Jan Reedy <[email protected]> Co-authored-by: Wulian <[email protected]>
1 parent dc0a176 commit 5e62d9b

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

Lib/turtledemo/clock.py

+20-13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/usr/bin/env python3
2-
# -*- coding: cp1252 -*-
32
""" turtle-example-suite:
43
5-
tdemo_clock.py
4+
turtledemo/clock.py
65
76
Enhanced clock-program, showing date
87
and time
@@ -13,6 +12,9 @@
1312
from turtle import *
1413
from datetime import datetime
1514

15+
dtfont = "TkFixedFont", 14, "bold"
16+
current_day = None
17+
1618
def jump(distanz, winkel=0):
1719
penup()
1820
right(winkel)
@@ -53,11 +55,23 @@ def clockface(radius):
5355
jump(-radius)
5456
rt(6)
5557

58+
def display_date_time():
59+
global current_day
60+
writer.clear()
61+
now = datetime.now()
62+
current_day = now.day
63+
writer.home()
64+
writer.forward(distance=65)
65+
writer.write(wochentag(now), align="center", font=dtfont)
66+
writer.back(distance=150)
67+
writer.write(datum(now), align="center", font=dtfont)
68+
writer.forward(distance=85)
69+
5670
def setup():
5771
global second_hand, minute_hand, hour_hand, writer
5872
mode("logo")
5973
make_hand_shape("second_hand", 125, 25)
60-
make_hand_shape("minute_hand", 130, 25)
74+
make_hand_shape("minute_hand", 115, 25)
6175
make_hand_shape("hour_hand", 90, 25)
6276
clockface(160)
6377
second_hand = Turtle()
@@ -75,10 +89,10 @@ def setup():
7589
hand.speed(0)
7690
ht()
7791
writer = Turtle()
78-
#writer.mode("logo")
7992
writer.ht()
8093
writer.pu()
8194
writer.bk(85)
95+
display_date_time()
8296

8397
def wochentag(t):
8498
wochentag = ["Monday", "Tuesday", "Wednesday",
@@ -100,18 +114,11 @@ def tick():
100114
stunde = t.hour + minute/60.0
101115
try:
102116
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)
112117
second_hand.setheading(6*sekunde) # or here
113118
minute_hand.setheading(6*minute)
114119
hour_hand.setheading(30*stunde)
120+
if t.day != current_day:
121+
display_date_time()
115122
tracer(True)
116123
ontimer(tick, 100)
117124
except Terminator:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix the canvas not clearing after running turtledemo clock.

0 commit comments

Comments
 (0)