51
51
turtle. So the turtles can more easily be used as a visual feedback
52
52
instrument by the (beginning) programmer.
53
53
54
- - Different turtle shapes, gif-images as turtle shapes, user defined
54
+ - Different turtle shapes, image files as turtle shapes, user defined
55
55
and user controllable turtle shapes, among them compound
56
56
(multicolored) shapes. Turtle shapes can be stretched and tilted, which
57
57
makes turtles very versatile geometrical objects.
@@ -468,7 +468,7 @@ def _blankimage(self):
468
468
469
469
def _image (self , filename ):
470
470
"""return an image object containing the
471
- imagedata from a gif- file named filename.
471
+ imagedata from an image file named filename.
472
472
"""
473
473
return TK .PhotoImage (file = filename , master = self .cv )
474
474
@@ -872,10 +872,7 @@ def __init__(self, type_, data=None):
872
872
if isinstance (data , list ):
873
873
data = tuple (data )
874
874
elif type_ == "image" :
875
- if isinstance (data , str ):
876
- if data .lower ().endswith (".gif" ) and isfile (data ):
877
- data = TurtleScreen ._image (data )
878
- # else data assumed to be PhotoImage
875
+ assert (isinstance (data , TK .PhotoImage ))
879
876
elif type_ == "compound" :
880
877
data = []
881
878
else :
@@ -1100,14 +1097,18 @@ def register_shape(self, name, shape=None):
1100
1097
"""Adds a turtle shape to TurtleScreen's shapelist.
1101
1098
1102
1099
Arguments:
1103
- (1) name is the name of a gif- file and shape is None.
1100
+ (1) name is the name of an image file (PNG, GIF, PGM, and PPM) and shape is None.
1104
1101
Installs the corresponding image shape.
1105
1102
!! Image-shapes DO NOT rotate when turning the turtle,
1106
1103
!! so they do not display the heading of the turtle!
1107
- (2) name is an arbitrary string and shape is a tuple
1104
+ (2) name is an arbitrary string and shape is the name of an image file (PNG, GIF, PGM, and PPM).
1105
+ Installs the corresponding image shape.
1106
+ !! Image-shapes DO NOT rotate when turning the turtle,
1107
+ !! so they do not display the heading of the turtle!
1108
+ (3) name is an arbitrary string and shape is a tuple
1108
1109
of pairs of coordinates. Installs the corresponding
1109
1110
polygon shape
1110
- (3 ) name is an arbitrary string and shape is a
1111
+ (4 ) name is an arbitrary string and shape is a
1111
1112
(compound) Shape object. Installs the corresponding
1112
1113
compound shape.
1113
1114
To use a shape, you have to issue the command shape(shapename).
@@ -1120,12 +1121,9 @@ def register_shape(self, name, shape=None):
1120
1121
1121
1122
"""
1122
1123
if shape is None :
1123
- # image
1124
- if name .lower ().endswith (".gif" ):
1125
- shape = Shape ("image" , self ._image (name ))
1126
- else :
1127
- raise TurtleGraphicsError ("Bad arguments for register_shape.\n "
1128
- + "Use help(register_shape)" )
1124
+ shape = Shape ("image" , self ._image (name ))
1125
+ elif isinstance (shape , str ):
1126
+ shape = Shape ("image" , self ._image (shape ))
1129
1127
elif isinstance (shape , tuple ):
1130
1128
shape = Shape ("polygon" , shape )
1131
1129
## else shape assumed to be Shape-instance
@@ -1454,7 +1452,7 @@ def bgpic(self, picname=None):
1454
1452
"""Set background image or return name of current backgroundimage.
1455
1453
1456
1454
Optional argument:
1457
- picname -- a string, name of a gif- file or "nopic".
1455
+ picname -- a string, name of an image file (PNG, GIF, PGM, and PPM) or "nopic".
1458
1456
1459
1457
If picname is a filename, set the corresponding image as background.
1460
1458
If picname is "nopic", delete backgroundimage, if present.
0 commit comments