gpt-3.5-turbo-0301· OpenAI
WildChat-4.8M (AI2)
python give me a desktop pet code
- User
python give me a desktop pet code
- Assistant
Here is a simple desktop pet code in Python using the turtle library:
codeimport turtle # Set up the screen wn = turtle.Screen() wn.bgcolor("light blue") # Set up the turtle pet = turtle.Turtle() pet.shape("turtle") pet.color("green") pet.speed(0) # Define the movement functions def move_up(): pet.setheading(90) pet.forward(10) def move_left(): pet.setheading(180) pet.forward(10) def move_down(): pet.setheading(270) pet.forward(10) def move_right(): pet.setheading(0) pet.forward(10) # Set up the keyboard bindings wn.onkey(move_up, "Up") wn.onkey(move_left, "Left") wn.onkey(move_down, "Down") wn.onkey(move_right, "Right") wn.listen() # Start the main loop turtle.mainloop()This creates a green turtle that can be moved around the screen using the arrow keys. You can modify this code to add more features and make your desktop pet more interesting.