简体   繁体   English

如何使用提示在乌龟图形中设置颜色和笔型?

[英]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. (提示:您可以在https://www.w3schools.com/colors/colors_names.asp中找到允许的颜色名称列表。其中包括一些非常不寻常的颜色名称,例如“ PeachPuff”和“ HotPink”。)允许用户在运行时设置tess的颜色。 Do the same for the width of tess' pen. 对TESS笔的宽度执行相同的操作。 Hint: your dialog with the user will return a string, but tess' pensize method expects its argument to be an int. 提示:与用户的对话框将返回一个字符串,但是tess的pensize方法期望其参数为int。 That means you need to convert the string to an int before you pass it to pensize. 这意味着您需要先将字符串转换为int,然后再将其传递给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. 您可以在Python中使用input()

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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