omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Turtle.write. Text color

    Pythonista
    2
    2
    8730
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • cladocora
      cladocora last edited by ccc

      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 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @cladocora last edited by 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() 
        
        1 Reply Last reply Reply Quote 1
        • First post
          Last post
        Powered by NodeBB Forums | Contributors