21
21
# misrepresented as being the original software.
22
22
# 3. This notice may not be removed or altered from any source distribution.
23
23
24
-
25
24
"""
26
25
Turtle graphics is a popular way for introducing programming to
27
26
kids. It was part of the original Logo programming language developed
97
96
98
97
Behind the scenes there are some features included with possible
99
98
extensions in mind. These will be commented and documented elsewhere.
100
-
101
99
"""
102
100
103
- _ver = "turtle 1.1b- - for Python 3.1 - 4. 5. 2009"
104
-
105
- # print(_ver)
106
-
107
101
import tkinter as TK
108
102
import types
109
103
import math
141
135
_tg_utilities = ['write_docstringdict' , 'done' ]
142
136
143
137
__all__ = (_tg_classes + _tg_screen_functions + _tg_turtle_functions +
144
- _tg_utilities + ['Terminator' ]) # + _math_functions)
138
+ _tg_utilities + ['Terminator' ])
145
139
146
140
_alias_list = ['addshape' , 'backward' , 'bk' , 'fd' , 'ht' , 'lt' , 'pd' , 'pos' ,
147
141
'pu' , 'rt' , 'seth' , 'setpos' , 'setposition' , 'st' ,
@@ -598,9 +592,6 @@ def _write(self, pos, txt, align, font, pencolor):
598
592
x0 , y0 , x1 , y1 = self .cv .bbox (item )
599
593
return item , x1 - 1
600
594
601
- ## def _dot(self, pos, size, color):
602
- ## """may be implemented for some other graphics toolkit"""
603
-
604
595
def _onclick (self , item , fun , num = 1 , add = None ):
605
596
"""Bind fun to mouse-click event on turtle.
606
597
fun must be a function with two arguments, the coordinates
@@ -2726,7 +2717,7 @@ def _cc(self, args):
2726
2717
if not ((0 <= r <= 255 ) and (0 <= g <= 255 ) and (0 <= b <= 255 )):
2727
2718
raise TurtleGraphicsError ("bad color sequence: %s" % str (args ))
2728
2719
return "#%02x%02x%02x" % (r , g , b )
2729
-
2720
+
2730
2721
def teleport (self , x = None , y = None , * , fill_gap : bool = False ) -> None :
2731
2722
"""Instantly move turtle to an absolute position.
2732
2723
@@ -2738,14 +2729,14 @@ def teleport(self, x=None, y=None, *, fill_gap: bool = False) -> None:
2738
2729
call: teleport(x, y) # two coordinates
2739
2730
--or: teleport(x) # teleport to x position, keeping y as is
2740
2731
--or: teleport(y=y) # teleport to y position, keeping x as is
2741
- --or: teleport(x, y, fill_gap=True)
2732
+ --or: teleport(x, y, fill_gap=True)
2742
2733
# teleport but fill the gap in between
2743
2734
2744
2735
Move turtle to an absolute position. Unlike goto(x, y), a line will not
2745
2736
be drawn. The turtle's orientation does not change. If currently
2746
2737
filling, the polygon(s) teleported from will be filled after leaving,
2747
2738
and filling will begin again after teleporting. This can be disabled
2748
- with fill_gap=True, which makes the imaginary line traveled during
2739
+ with fill_gap=True, which makes the imaginary line traveled during
2749
2740
teleporting act as a fill barrier like in goto(x, y).
2750
2741
2751
2742
Example (for a Turtle instance named turtle):
@@ -2773,7 +2764,7 @@ def teleport(self, x=None, y=None, *, fill_gap: bool = False) -> None:
2773
2764
self ._position = Vec2D (new_x , new_y )
2774
2765
self .pen (pendown = pendown )
2775
2766
if was_filling and not fill_gap :
2776
- self .begin_fill ()
2767
+ self .begin_fill ()
2777
2768
2778
2769
def clone (self ):
2779
2770
"""Create and return a clone of the turtle.
@@ -3455,27 +3446,22 @@ def dot(self, size=None, *color):
3455
3446
if size is None :
3456
3447
size = self ._pensize + max (self ._pensize , 4 )
3457
3448
color = self ._colorstr (color )
3458
- if hasattr (self .screen , "_dot" ):
3459
- item = self .screen ._dot (self ._position , size , color )
3460
- self .items .append (item )
3461
- if self .undobuffer :
3462
- self .undobuffer .push (("dot" , item ))
3463
- else :
3464
- pen = self .pen ()
3465
- if self .undobuffer :
3466
- self .undobuffer .push (["seq" ])
3467
- self .undobuffer .cumulate = True
3468
- try :
3469
- if self .resizemode () == 'auto' :
3470
- self .ht ()
3471
- self .pendown ()
3472
- self .pensize (size )
3473
- self .pencolor (color )
3474
- self .forward (0 )
3475
- finally :
3476
- self .pen (pen )
3477
- if self .undobuffer :
3478
- self .undobuffer .cumulate = False
3449
+ # If screen were to gain a dot function, see GH #104218.
3450
+ pen = self .pen ()
3451
+ if self .undobuffer :
3452
+ self .undobuffer .push (["seq" ])
3453
+ self .undobuffer .cumulate = True
3454
+ try :
3455
+ if self .resizemode () == 'auto' :
3456
+ self .ht ()
3457
+ self .pendown ()
3458
+ self .pensize (size )
3459
+ self .pencolor (color )
3460
+ self .forward (0 )
3461
+ finally :
3462
+ self .pen (pen )
3463
+ if self .undobuffer :
3464
+ self .undobuffer .cumulate = False
3479
3465
3480
3466
def _write (self , txt , align , font ):
3481
3467
"""Performs the writing for write()
@@ -3751,11 +3737,6 @@ class _Screen(TurtleScreen):
3751
3737
_title = _CFG ["title" ]
3752
3738
3753
3739
def __init__ (self ):
3754
- # XXX there is no need for this code to be conditional,
3755
- # as there will be only a single _Screen instance, anyway
3756
- # XXX actually, the turtle demo is injecting root window,
3757
- # so perhaps the conditional creation of a root should be
3758
- # preserved (perhaps by passing it as an optional parameter)
3759
3740
if _Screen ._root is None :
3760
3741
_Screen ._root = self ._root = _Root ()
3761
3742
self ._root .title (_Screen ._title )
0 commit comments