所以我在Python中随机产生了圆圈,我决定让每个圆圈成为它自己的对象。所以我为他们创建了一个课程。
我希望每个圆圈都有自己的刻度功能,这样每个圆圈都可以做自己的事情。 (改变颜色,大小,去生成等)但是我有很多问题让tick方法起作用。 这是我的代码:
from random import *
from tkinter import *
from time import *
size = 2000
window = Tk()
count = 0
class Shape(object):
def __init__(self,name, canv, size, col, x0, y0,d,outline):
self.name = name
self.canv = canv
self.size = size
self.col = col
self.x0 = x0
self.y0 = y0
self.d = d
self.outline = outline
self.age=0
def death(self):
pass
def spawn(self):
self.canv.create_oval(self.x0, self.y0, self.x0 + self.d, self.y0 + self.d, outline=self.outline, fill = self.col)
def tick(self):
self.age = self.age +time.time()
while True:
tick()
# var canv = A new Canvas Object (The Window Object to be put in, The Canvice width, The canvice Height)
canv = Canvas(window, width=size, height=size)
canv.pack()
d = 0
while True:
col = choice(['#EAEA00'])
x0 = randint(0, size)
y0 = randint(0, size)
#d = randint(0, size/5)
d = (d + 0.001)
count = count+1
outline = 'white'
shapes[count] = Shape("shape" + str(count), canv, size, col, x0, y0, d, outline)
shapes[count].spawn()
#canv.create_oval(x0, y0, x0 + d, y0 + d, outline='white', fill = col)
window.update()
所以基本上我从这部分代码中得到了两个不同的错误:
while True:
tick()
以太它TypeError: tick() missing one required positional argument: 'self'
或者如果我把自己放入参数self is undefined
。
那么我做错了什么?