简体   繁体   中英

How do I set color and pensize in turtle graphics using prompts?

I need some help trying to prompt users how to edit the size of the pen and the color. This is the prompt that I was given.

Modify this program so that before it creates the window, it prompts the user to enter the desired background color. It should store the user's responses in a variable, and modify the color of the window according to the user's wishes. (Hint: you can find a list of permitted color names at https://www.w3schools.com/colors/colors_names.asp . It includes some quite unusual ones, like “PeachPuff” and “HotPink”.) Do similar changes to allow the user, at runtime, to set tess' color. Do the same for the width of tess' pen. Hint: your dialog with the user will return a string, but tess' pensize method expects its argument to be an int. That means you need to convert the string to an int before you pass it to pensize. The program should also be changed to complete the triangle.

Below is the code that I made, I am just stuck on what to do next.

import turtle

wn = turtle.Screen()
wn.bgcolor("lightgreen")        

tess = turtle.Turtle()
tess.color("blue")              
tess.pensize(3)                 

tess.forward(50)
tess.left(120)
tess.forward(50)

wn.exitonclick() 

I just need to be able to know how to prompt the user how to set the color and the pensize.

You can use input() in Python.

>>> response = input('What color should the pen be?')
What color should the pen be? red
>>> print(response)
'red'

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