Forum Archive

Turtle.write. Text color

cladocora

Why the text color remain black?

import turtle


def t():
    t = turtle.Turtle()
    t.fillcolor('green')
    t.begin_fill()
    t.color('green')
    for i in range(4):
        t.forward(50)
        t.left(90)
    t.end_fill()


def scritta():
    t = turtle.Turtle()
    t.color('green')
    t.fillcolor('green')
    t.begin_fill()
    t.penup()
    t.goto(0, -20)
    t.pendown()
    t.write('quadrato')
    t.end_fill()

t()
scritta()
cvp

@cladocora seems to be a bug because ui.draw_string in turtle.py uses its own key parameter color= to draw a string in color, try this little script

import turtle
import ui

# copy from standard module turtle.py
def write(self,text, move=False, align=None, font=None):
        """Write text at the current turtle position.

        Arguments:
        arg -- info, which is to be written to the TurtleScreen
        move (optional) -- True/False
        align (optional) -- one of the strings "left", "center" or right"
        font (optional) -- a triple (fontname, fontsize, fonttype)

        Write text - the string representation of arg - at the current
        turtle position according to align ("left", "center" or right")
        and with the given font.
        If move is True, the pen is moved to the bottom-right corner
        of the text. By default, move is False.

        Example (for a Turtle instance named turtle):
        >>> turtle.write('Home = ', True, align="center")
        >>> turtle.write((0,0), True)
        """
        # TODO: Implement `align` and `font` parameters
        text = str(text)
        w, h = ui.measure_string(text)
        color = self._current_color
        pos = self._pos
        def _draw():
            #ui.set_color(color)
            # ui.draw_string uses its own key parameter color=
            ui.draw_string(text, (pos.x, pos.y - h, 0, 0),color=color)
        self._add_drawing(_draw)
        if move:
            self._pos += (w, 0)
        self.update_view()

def t():
    t = turtle.Turtle()
    t.fillcolor('green')
    t.begin_fill()
    t.color('green')
    for i in range(4):
        t.forward(50)
        t.left(90)
    t.end_fill()

def scritta():
    t = turtle.Turtle()
    t.color('green')
    t.fillcolor('green')
    t.begin_fill()
    t.penup()
    t.goto(0, -20)
    t.pendown()
    #t.write('quadrato')    
    write(t,'quadrato')
    t.end_fill()

t()
scritta()