Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ';numpy.ndarray和#x27;对象没有属性';fbind';_Python_Python 3.x_Numpy_Kivy - Fatal编程技术网

Python ';numpy.ndarray和#x27;对象没有属性';fbind';

Python ';numpy.ndarray和#x27;对象没有属性';fbind';,python,python-3.x,numpy,kivy,Python,Python 3.x,Numpy,Kivy,我正在尝试编写一个代码,将NumPy数组添加到小部件中 这是我的密码: from kivy.app import App from kivy.uix.gridlayout import GridLayout from kivy.uix.image import Image from kivy.uix.button import Button import numpy as np class cell(Button): # MAKING A BUTTON def __init__(s

我正在尝试编写一个代码,将NumPy数组添加到小部件中 这是我的密码:

from kivy.app import App
from kivy.uix.gridlayout import GridLayout
from kivy.uix.image import Image
from kivy.uix.button import Button
import numpy as np


class cell(Button):  # MAKING A BUTTON
    def __init__(self):
        Button.__init__(self)
        self.background_normal = 'button.jpg'

    def on_press(self):
        self.background_normal = 'onPress.jpg'


class graphics(GridLayout):

    def __init__(self):  # BUILDING GRAPHIC BOARD
        GridLayout.__init__(self)
        self.cols = 3
        self.rows = 3
        c = cell()
        my_image = Image(source='empty.jpg')
        emptySquareArray = np.array([[my_image, my_image], [my_image, my_image]])
        squareArray = np.array([[c, c], [c, c]])
        self.sq = np.array([[squareArray, squareArray, squareArray], # PLAYING BOARD
                            [squareArray, emptySquareArray, squareArray],
                            [squareArray, squareArray, squareArray]])
        for i in range(3):
            for j in range(3):
                self.add_widget(self.sq[i][j])
但我一直在犯错误:

AttributeError: 'numpy.ndarray' object has no attribute 'fbind'

参考最后一行代码。我不知道我做错了什么。谢谢

add\u widget()
方法需要一个
widget
作为其参数
self.sq
是一个
numpy.ndarray
,而不是一个
Widget
。在调用
add_Widget()
之前,执行
print(self.sq[i][j])
以查看您试图添加的内容。