Приведенный ниже код отлично работает в 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
Ошибка типа в реализации Trinket графики Turtle ⇐ Python
Программы на Python
-
Anonymous
1762504147
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()
Подробнее здесь: [url]https://stackoverflow.com/questions/77908824/typeerror-on-trinket-implementation-of-turtle-graphics[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия