mirror of
https://github.com/python/cpython.git
synced 2025-10-15 03:10:29 +00:00
gh-123370: Fix the canvas not clearing after running turtledemo.clock (#123457)
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.
This commit is contained in:
parent
528bbab96f
commit
c124577ebe
2 changed files with 21 additions and 13 deletions
|
@ -1,7 +1,6 @@
|
||||||
# -*- coding: cp1252 -*-
|
|
||||||
""" turtle-example-suite:
|
""" turtle-example-suite:
|
||||||
|
|
||||||
tdemo_clock.py
|
turtledemo/clock.py
|
||||||
|
|
||||||
Enhanced clock-program, showing date
|
Enhanced clock-program, showing date
|
||||||
and time
|
and time
|
||||||
|
@ -12,6 +11,9 @@ and time
|
||||||
from turtle import *
|
from turtle import *
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
dtfont = "TkFixedFont", 14, "bold"
|
||||||
|
current_day = None
|
||||||
|
|
||||||
def jump(distanz, winkel=0):
|
def jump(distanz, winkel=0):
|
||||||
penup()
|
penup()
|
||||||
right(winkel)
|
right(winkel)
|
||||||
|
@ -52,11 +54,23 @@ def clockface(radius):
|
||||||
jump(-radius)
|
jump(-radius)
|
||||||
rt(6)
|
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():
|
def setup():
|
||||||
global second_hand, minute_hand, hour_hand, writer
|
global second_hand, minute_hand, hour_hand, writer
|
||||||
mode("logo")
|
mode("logo")
|
||||||
make_hand_shape("second_hand", 125, 25)
|
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)
|
make_hand_shape("hour_hand", 90, 25)
|
||||||
clockface(160)
|
clockface(160)
|
||||||
second_hand = Turtle()
|
second_hand = Turtle()
|
||||||
|
@ -74,10 +88,10 @@ def setup():
|
||||||
hand.speed(0)
|
hand.speed(0)
|
||||||
ht()
|
ht()
|
||||||
writer = Turtle()
|
writer = Turtle()
|
||||||
#writer.mode("logo")
|
|
||||||
writer.ht()
|
writer.ht()
|
||||||
writer.pu()
|
writer.pu()
|
||||||
writer.bk(85)
|
writer.bk(85)
|
||||||
|
display_date_time()
|
||||||
|
|
||||||
def wochentag(t):
|
def wochentag(t):
|
||||||
wochentag = ["Monday", "Tuesday", "Wednesday",
|
wochentag = ["Monday", "Tuesday", "Wednesday",
|
||||||
|
@ -99,18 +113,11 @@ def tick():
|
||||||
stunde = t.hour + minute/60.0
|
stunde = t.hour + minute/60.0
|
||||||
try:
|
try:
|
||||||
tracer(False) # Terminator can occur here
|
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
|
second_hand.setheading(6*sekunde) # or here
|
||||||
minute_hand.setheading(6*minute)
|
minute_hand.setheading(6*minute)
|
||||||
hour_hand.setheading(30*stunde)
|
hour_hand.setheading(30*stunde)
|
||||||
|
if t.day != current_day:
|
||||||
|
display_date_time()
|
||||||
tracer(True)
|
tracer(True)
|
||||||
ontimer(tick, 100)
|
ontimer(tick, 100)
|
||||||
except Terminator:
|
except Terminator:
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix the canvas not clearing after running turtledemo clock.
|
Loading…
Add table
Add a link
Reference in a new issue