]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] [3.13] gh-123370: Fix the canvas not clearing after running turtledemo.clock...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Thu, 17 Oct 2024 17:09:05 +0000 (19:09 +0200)
committerGitHub <noreply@github.com>
Thu, 17 Oct 2024 17:09:05 +0000 (17:09 +0000)
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 c124577ebe915a00de4033c0f7fa7c47621d79e0)

(cherry picked from commit 30d7e9e721e8201bc7fb23f08a7d88d51eed827d)

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Co-authored-by: Wulian <xiguawulian@gmail.com>
Lib/turtledemo/clock.py
Misc/NEWS.d/next/Library/2024-08-28-19-27-35.gh-issue-123370.SPZ9Ux.rst [new file with mode: 0644]

index 9f8585bd11e053e3ce668c0a9feccc5f7db438e9..318f126006333f4facbdc3960f5df396981338ad 100755 (executable)
@@ -1,8 +1,7 @@
 #!/usr/bin/env python3
-# -*- coding: cp1252 -*-
 """       turtle-example-suite:
 
-             tdemo_clock.py
+           turtledemo/clock.py
 
 Enhanced clock-program, showing date
 and time
@@ -13,6 +12,9 @@ and time
 from turtle import *
 from datetime import datetime
 
+dtfont = "TkFixedFont", 14, "bold"
+current_day = None
+
 def jump(distanz, winkel=0):
     penup()
     right(winkel)
@@ -53,11 +55,23 @@ def clockface(radius):
             jump(-radius)
         rt(6)
 
+def display_date_time():
+    global current_day
+    writer.clear()
+    now = datetime.now()
+    current_day = now.day
+    writer.home()
+    writer.forward(distance=65)
+    writer.write(wochentag(now), align="center", font=dtfont)
+    writer.back(distance=150)
+    writer.write(datum(now), align="center", font=dtfont)
+    writer.forward(distance=85)
+
 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()
@@ -75,10 +89,10 @@ def setup():
         hand.speed(0)
     ht()
     writer = Turtle()
-    #writer.mode("logo")
     writer.ht()
     writer.pu()
     writer.bk(85)
+    display_date_time()
 
 def wochentag(t):
     wochentag = ["Monday", "Tuesday", "Wednesday",
@@ -100,18 +114,11 @@ def tick():
     stunde = t.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)
+        if t.day != current_day:
+            display_date_time()
         tracer(True)
         ontimer(tick, 100)
     except Terminator:
diff --git a/Misc/NEWS.d/next/Library/2024-08-28-19-27-35.gh-issue-123370.SPZ9Ux.rst b/Misc/NEWS.d/next/Library/2024-08-28-19-27-35.gh-issue-123370.SPZ9Ux.rst
new file mode 100644 (file)
index 0000000..1fd5cc5
--- /dev/null
@@ -0,0 +1 @@
+Fix the canvas not clearing after running turtledemo clock.