Ошибка типа в реализации Trinket графики TurtlePython

Программы на Python
Ответить
Anonymous
 Ошибка типа в реализации Trinket графики Turtle

Сообщение Anonymous »

Приведенный ниже код отлично работает в Windows 10 с Python 3.10. При нажатии на черепаху ее цвет меняется. Однако когда я запускаю код в браузерной среде Trinket, здесь: https://trinket.io/python/0da2ab1181, я получаю следующую ошибку:

ExternalError: TypeError: Cannot read properties of undefined (reading 'constructor') on line 15 in main.py

когда я нажимаю на Черепаху.
Как мне сделать, чтобы это работало правильно? Я просмотрел документацию к модулю, и они дают:
Help on function fillcolor in turtle:

turtle.fillcolor = fillcolor(*args)
Return or set the fillcolor.

Arguments:
Four input formats are allowed:
- fillcolor()
Return the current fillcolor as color specification string,
possibly in hex-number format (see example).
May be used as input to another color/pencolor/fillcolor call.
- fillcolor(colorstring)
s is a Tk color specification string, such as "red" or "yellow"
- fillcolor((r, g, b))
*a tuple* of r, g, and b, which represent, an RGB color,
and each of r, g, and b are in the range 0..colormode,
where colormode is either 1.0 or 255
- fillcolor(r, g, b)
r, g, and b represent an RGB color, and each of r, g, and b
are in the range 0..colormode

If turtleshape is a polygon, the interior of that polygon is drawn
with the newly set fillcolor.

Example:
>>> fillcolor('violet')
>>> col = pencolor()
>>> fillcolor(col)
>>> fillcolor(0, .5, 0)


Код программы:
class ToggleTurtle(turtle.Turtle):
def __init__(self):
super().__init__()
self.shape("turtle")
self.color1 = "red"
self.color2 = "blue"
self.fillcolor(self.color1)
self.onclick(self.toggle_color)

def toggle_color(self, x, y):
if self.fillcolor() == self.color1:
self.fillcolor(self.color2)
else:
self.fillcolor(self.color1)

tt = ToggleTurtle()

turtle.done()


Подробнее здесь: https://stackoverflow.com/questions/779 ... e-graphics
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»