1 回答
TA贡献1804条经验 获得超2个赞
看来你调用的方法targetTask()内部NBack的构造,在下面的行
self.t = Thread(target=self.targetTask,)
self.t.daemon = True
self.t.start()
在它有机会定义sequence属性之前。
它将通过sequence在调用之前定义和您需要的任何其他内容来修复targetTask()。
构造函数看起来像这样:
def __init__(self, master):
##Title of the window
self.master = master
master.title("N-Back")
##It measures the screen size (width x height + x + y)
##The opened window will be based on the screen size
master.geometry("{0}x{1}-0+0".format(master.winfo_screenwidth(), master.winfo_screenheight()))
self.canvas = tk.Canvas(master, width=master.winfo_screenwidth(), height=master.winfo_screenheight(), \
borderwidth=0, highlightthickness=0, bg="grey")
self.canvasWidth = master.winfo_screenwidth()
self.canvasHeight = master.winfo_screenheight()
self.createLines()
self.createText()
self.canvas.grid()
# Notice we define self.sequence before calling self.targetTask
self.sequence = generateZBackSequence(20, 5)
## Positions of the circles ("stims")
## - -
## 0 - 1 - 2
## ------------
## 3 - 4 - 5
## ------------
## 6 - 7 - 8
## - -
self.positions = np.array([[(self.canvasWidth/2)-130, (self.canvasHeight/2)-130],\
[(self.canvasWidth/2), (self.canvasHeight/2)-130],\
[(self.canvasWidth/2)+130, (self.canvasHeight/2)-130],\
[(self.canvasWidth/2)-130, (self.canvasHeight/2)],\
[(self.canvasWidth/2), (self.canvasHeight/2)],\
[(self.canvasWidth/2)+130, (self.canvasHeight/2)],\
[(self.canvasWidth/2)-130, (self.canvasHeight/2)+130], \
[(self.canvasWidth/2), (self.canvasHeight/2)+130], \
[(self.canvasWidth/2)+130, (self.canvasHeight/2)+130]])
self.t = Thread(target=self.targetTask,)
self.t.daemon = True
self.t.start()
添加回答
举报