-1
隨着下面的代碼,我可以得到附加的精靈刪除和點擊事件列表中刪除,但遺憾的是,這不是我所需要的。我已經花了幾個小時試圖讓它自動刪除,並在它通過運動類15次後從列表中刪除。 (我可以提供,如果你需要它幫助我。刪除和刪除附加的對象-python
class projectilesGroup(object):
def __init__(self, canvas):
self.canvas = canvas
self.projectiles = list()
self.moving = True
def clicked(self, event, projectile):
print('clicked:', projectile),
# remove oval from canvas
self.canvas.delete(projectile.oval)
# remove enemy from list
self.projectiles.remove(projectile)
def add_new_projectile(self):
print(len(self.projectiles))
if len(self.projectiles) < 5:
e = projectile(self.canvas)
# stop new enemy if all enemies are stoped
e.moving = self.moving
self.canvas.tag_bind(e.oval, '<Button-1>', lambda event:self.clicked(event, e))
self.projectiles.append(e)
else:
print("You have 5 spells active - I can't add more.")
感謝。
def move(self):
if repcount < 15:
if self.moving: # to stop root.after
if self.direction == 1: # up
self.y1 -= self.radius
self.y2 -= self.radius
elif self.direction == 2: # down
self.y1 += self.radius
self.y2 += self.radius
elif self.direction == 3: # left
self.x1 -= self.radius
self.x2 -= self.radius
elif self.direction == 4: # right
self.x1 += self.radius
self.x2 += self.radius
self.canvas.coords(self.oval, self.x1, self.y1, self.x2, self.y2)
repcount += 1
root.after(20, self.move)
else:
print('done')
是的我有一個圍繞運動類的專櫃 –
看到新的編輯。 –
甜美的感謝,我得到它的工作 –