Turtle module not displaying properly on my screen

Question:
Every time i run the turtle module on my console, the output tab will only run when it is performing whatever task it is assigned and then will disappear(console screen goes black). I have had this for a while now(ever since i started replit) but never bothered to do anything about it.
Repl link:
https://replit.com/@jonathanessombe/new-attempt#main.py

import turtle

Tu = turtle.Turtle()
Tu.shape('turtle')
screen = turtle.Screen()
screen.setup(1000, 1000)
Tu.penup()

def write_poem(poem_lines):

  y_initial = 400
  x_initial = -300
  
  for lines in poem_lines:
    if 'by' not in poem_lines[-1]:
      Tu.goto(-50, 0)
      Tu.write("      please enter a poem with the word 'by' in the final line")
    else:  
      Tu.goto(x_initial, y_initial)
      Tu.write(lines)
      y_initial -= 20
      Tu.goto(x_initial + 20, y_initial)

with open('poem_canvas.txt', 'r') as poem_canva:
  poem_line = poem_canva.read()
  poem_sentence = list(filter(lambda sentence: True if sentence != '' else False,
                              poem_line.split('\n')))


write_poem(poem_sentence)

1 Like

This is a side effect of how replit runs your repls.

You just need to put

turtle.mainloop()

at the end of your program so that the program doesn’t end immediately.
See turtle — Turtle graphics — Python 3.12.0 documentation

An alternative way is to put

input()

at the end of the program.

3 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.