Следующая может делать то, что вы хотите, - это вопрос, который не был упомянут в предыдущем обсуждении является turtle.colormode()
, который влияет хотите ли вы Int или плавать вход:
from turtle import Turtle, Screen
def input_rgb(prompt=""):
triple = None
text = prompt + "Enter comma-separated RGB values: "
while True:
try:
triple_string = input(text).split(',', maxsplit=2)
if len(triple_string) != 3:
continue
if isinstance(screen.colormode(), float):
triple = map(float, triple_string)
else:
triple = map(int, triple_string)
except ValueError:
continue
break
return triple
screen = Screen()
yertle = Turtle(shape="turtle")
yertle.fillcolor(input_rgb("Fill color? "))
yertle.pencolor(input_rgb("Outline color? "))
yertle.begin_fill()
yertle.circle(100)
yertle.end_fill()
screen.exitonclick()
ПРИМЕНЕНИЕ
% python3 test.py
Fill color? Enter comma-separated RGB values: 1.0,0.0,0.0
Outline color? Enter comma-separated RGB values: 0.0,0.0,1.0
OUTPUT
Следующая задача (для вас), чтобы преобразовать input_rgb()
использовать черепашью графические подпрограммы ввода вместо input()
:
turtle.textinput(title, prompt)
turtle.numinput(title, prompt, default=None, minval=None, maxval=None)
Я просто хотел, чтобы вы знали, что я сейчас решил эту проблему. Я достиг этого, разделив значение RGB на три разных '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' '' –