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
#1
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')
    penup()
    tur.setpos(-100,y)
    tur.color(tclr)
    pendown()
    forward(200)
    penup()
#Return to the same Y position
#Center X to match the text
    tur.setpos(0,y)
    teststring = 'Test String ' + str(i) #Create a string
    pendown() #And write the text
    tur.write(teststring, font = style, align = 'center')
    penup()
Thanks for your help.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Turtle Graphics - Screen & Window Sizing jerryf 1 772 Feb-09-2023, 08:02 PM
Last Post: jerryf
  Is there a way to move text created by turtle.write()? derekered 7 5,826 Dec-16-2020, 09:44 AM
Last Post: itexamples
  Duplicating Rows And Put Them In Certain Index Position Query eddywinch82 0 1,254 Nov-25-2020, 05:24 PM
Last Post: eddywinch82
  Python 3 Turtle - Screen Events and Coords peteralien 0 1,652 Aug-18-2020, 11:25 PM
Last Post: peteralien
  turtle.Screen() not working Jdawgg531 0 2,694 May-04-2020, 12:43 AM
Last Post: Jdawgg531
  Python Turtle and order of implementation query Parsleigh 2 2,706 Mar-04-2019, 02:43 PM
Last Post: Parsleigh
  wn = turtle.screen() AttributeError: module 'turtle' has no attribute 'screen' Shadower 1 6,127 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 5,540 Jan-04-2019, 02:44 AM
Last Post: SheeppOSU
  Full Screen Text I/O DavidAlanGay 4 3,752 Oct-24-2018, 06:26 AM
Last Post: wavic
  Change on-screen text Panda 5 3,763 Jun-08-2018, 03:19 PM
Last Post: Grok_It

Forum Jump:

User Panel Messages

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