Skip to content Skip to sidebar Skip to footer

Why Does My Python Turtle Shape Size Decrease When Pressing 'shift'

I am trying to create a turtle in Python so I could increase/ decrease it's size by pressing +/- on keyboard import turtle turtle.setup(700,500) wn = turtle.Screen() testing_tur

Solution 1:

You need to use 'plus' and 'minus' to bind the functions to the key-release event of the + and - key:

wn.onkey(addsize,'plus')
wn.onkey(dropsize,'minus')

To solve the NameError exception, either place your size variable otside your main loop or use the nonlocal statement instead of global:

defaddsize():
    nonlocal size
    if size<20:    # To ensure the size of turtle is between 1 to 20
        size+=1print(size)
        testing_turtle.shapesize(size)

Post a Comment for "Why Does My Python Turtle Shape Size Decrease When Pressing 'shift'"