Python Forum
Turtle.setpos() vs text position on screen query
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Turtle.setpos() vs text position on screen query
The program draws three centered lines on the screen and writes text at the same Y position. The text floats above the line with the spaceing between the line and the text varing with the font size. Decenders do not reach down to the line.

Same result with Thonny on Windows or Raspberry Pi.

What is the relationship between the Y turtle position, font size, and where turtle.write() puts text on the screen? Does each character exist in a box of HxW pixels related to the font size? Where would I find this info in the documentation?

from turtle import *
import turtle as tur

#Set various parameters
ypos = (200, 0, -200) # Line and text vertical position
fntsz = (20, 35, 50) #Font size
clr = ('red', 'green', 'blue')

for i in range(3):
    #Draw a reference line
    y = ypos[i]
    tclr = clr[i]
    sz = fntsz[i]
    style = ('courier', sz, 'bold')
#Return to the same Y position
#Center X to match the text
    teststring = 'Test String ' + str(i) #Create a string
    pendown() #And write the text
    tur.write(teststring, font = style, align = 'center')
Thanks for your help.

Possibly Related Threads…
Thread Author Replies Views Last Post
  Turtle Graphics - Screen & Window Sizing jerryf 0 96 Feb-03-2023, 07:36 PM
Last Post: jerryf
  Is there a way to move text created by turtle.write()? derekered 7 3,692 Dec-16-2020, 09:44 AM
Last Post: itexamples
  Duplicating Rows And Put Them In Certain Index Position Query eddywinch82 0 925 Nov-25-2020, 05:24 PM
Last Post: eddywinch82
  Python 3 Turtle - Screen Events and Coords peteralien 0 1,187 Aug-18-2020, 11:25 PM
Last Post: peteralien
  turtle.Screen() not working Jdawgg531 0 2,058 May-04-2020, 12:43 AM
Last Post: Jdawgg531
  Python Turtle and order of implementation query Parsleigh 2 2,120 Mar-04-2019, 02:43 PM
Last Post: Parsleigh
  wn = turtle.screen() AttributeError: module 'turtle' has no attribute 'screen' Shadower 1 5,541 Feb-06-2019, 01:25 AM
Last Post: woooee
  Help! Turtle not working, even when we click the turtle demo in IDLE nothing happens. BertyBee 3 4,660 Jan-04-2019, 02:44 AM
Last Post: SheeppOSU
  Full Screen Text I/O DavidAlanGay 4 3,078 Oct-24-2018, 06:26 AM
Last Post: wavic
  Change on-screen text Panda 5 2,946 Jun-08-2018, 03:19 PM
Last Post: Grok_It

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020