python / python/cpython

Turtle - rotate head when shape is set to image

Open
#130,715 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-feature
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Feature or enhancement

Proposal:

I found turtle module to be a great way to introduce my kid to programming. I spotted that he is especially enjoying some interactive scripts, that react to keys or clicking. My problem is that currently when head shape is set to an image, it's not getting rotated which is quite a limitation when it comes to achieving some interesting effects while keeping the code simple.

Would you consider adding an option to rotate turtle head shape when it's set to an image to the library?

Sample code could work like this:

import turtle

sc = turtle.Screen()
sc.addshape("./car.png", rotate_image_shape=True)

t = turtle.Turtle()
t.shape("./car.png")

def handle_click(x,y):
    t.setheading(t.towards(x,y))
    t.goto(x,y)

sc.onclick(handle_click)

turtle.mainloop()

so unless you explicitly say that you want to rotate image shape, it would work as it used to.

I did some research and implemented sample solution here:
https://github.com/python/cpython/compare/main...kbialowas:cpython:tilt-turtle-transformation

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

https://discuss.python.org/t/turtle-make-it-possible-to-tilt-image-shape/81890/2

Linked PRs
  • gh-130855

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the turtle module entry points shown in the proposal, especially Screen.addshape(), Turtle.shape(), and heading changes, then review the linked sample solution and PR gh-130855. Done means image shapes can opt into rotation while preserving the existing behavior when the option is omitted.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
desktop
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.