import turtle # create a turtle object t = turtle.Turtle() # draw a square for i in range(4): t.forward(100) t.left(90) # create a Screen object s = turtle.Screen() # keep the screen open s.mainloop()
import turtle # create a turtle object t = turtle.Turtle() # draw a spiral for i in range(100): t.forward(i * 5) t.right(144) # create a Screen object s = t.getscreen() # keep the screen open s.mainloop()In this example, we create a turtle object and draw a spiral. Then we get the Screen object associated with the turtle using the getscreen method of turtle and call the mainloop method to keep the window open. Overall, the turtle module in Python provides an easy way to create graphics and animations using turtle graphics. The turtle.Screen mainloop method is just one of the many useful methods provided by this module.