简体   繁体   中英

Python Turtle library methods not working

Trying to create a basic snake game and it won't change the colour of the screen or create a turtle object. I've tried using different ways to input color etc, not working. I'm stumped, seems like things should be pretty straightforward at this level. Here's the code:

#Write your code below this line 👇 input('Player name: ')

import turtle as t

screen=t.Screen()
screen.title('WELCOME')
screen.exitonclick()
screen.bgcolor('black')

turtle_obj= t.Turtle()

If you move the screen.exitonclick() to the last line of the code, everything works as you would expect.

This is because exitonclick() binds turtle's bye() method (which shuts the window) to wait for a click instead of just shutting down. It is effectively ending your program, but just waiting for a mouse click to do it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM