python调用方法后没有创建实例_Python,实例没有调用方法

我在python2.7和tkinter一起工作。我只想在一个类中画一个画布,然后在另一个类中画一个将围绕画布移动正方形的类。但不知为什么我Exception in Tkinter callback

Traceback (most recent call last):

File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1410, in __call__

return self.func(*args)

File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 495, in callit

func(*args)

AttributeError: Animation instance has no __call__ method

据我所见,当人们重写一个值或一个名称隐藏另一个值时,就会出现这个错误。但我看不出我可能骑过头了。其他人能看到问题吗?

驱动程序.py:from Tkinter import *

import animation

class Alien(object):

def __init__(self):

#Set up canvas

self.root = Tk()

self.canvas = Canvas(self.root, width=400, height=400)

self.canvas.pack()

#Vars

self.map = [[1, 0, 0, 1, 0], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0], [0, 1, 1, 0, 0], [1, 0, 0, 1, 0]]

self.x = 0

self.y = 0

r = 50

land = {}

#Draw Init

for i, row in enumerate(self.map):

for j, cell in enumerate(row):

color = "black" if cell else "green"

land[(i, j)] = self.canvas.create_rectangle(r * i, r * j , r * (i + 1), r * (j + 1),

outline=color, fill=color)

self.creature = self.canvas.create_rectangle(r * self.x, r * self.y, r * (self.x + 1), r * (self.y + 1),

outline="red", fill="red")

self.canvas.pack(fill=BOTH, expand=1)

#Action

self.root.after(0, animation.Animation(self.root, self.canvas, self.creature))

#Clost TK

self.root.mainloop()

a = Alien()

动画.py:from random import randrange

class Animation():

def __init__(self, root, canvas, creature):

self.x = self.y = 0

i = randrange(1, 5)

if i == 1:

self.y = -1

elif i == 2:

self.y = 1

elif i == 3:

self.x = -1

elif i == 4:

self.x = 1

self.canvas = canvas

self.creature = creature

for i in range(10):

root.after(250, self.animate())

def animate(self):

#root.after(250, self.animate(canvas, creature))

"""Moves creature around canvas"""

self.canvas.move(self.creature, self.x * 50, self.y * 50)

#self.canvas.update() no longer needed

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值