Код: Выделить всё
from typing import Tuple
from turtle import Turtle
class Card:
def __init__(self, val: int, img: str, location: Tuple[float, float],
back: str = "card_back.gif"):
self.value = val
self.front = img
self.back = back
self.location = location
self.turtle = Turtle()
self.is_face_down = True
self.turtle.penup()
self.turtle.goto(self.location)
self.turtle.onclick(self.flip)
self.turtle.showturtle()
def show_back(self):
self.turtle.shape(self.back)
self.is_face_down = True
def show_front(self):
self.turtle.shape(self.front)
self.is_face_down = False
def flip(self, x, y):
if self.is_face_down:
self.show_front()
else:
self.show_back()
Код: Выделить всё
...
two_club1 = Card(0, "2_of_clubs.gif", (-400, 250))
two_club1.show_back()
two_club1.turtle.onclick(two_club1.flip) # Without this, the click does not work
turtle.done()
Подробнее здесь: https://stackoverflow.com/questions/792 ... d-in-class
Мобильная версия