属性错误:';地图';对象没有属性';瓷砖';tkinter python 3.9

属性错误:';地图';对象没有属性';瓷砖';tkinter python 3.9,python,class,object,tkinter,attributes,Python,Class,Object,Tkinter,Attributes,我有地图课,如下所示: class Map: def _init_(self): self.tiles = [ [0, 0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 1, 0, 1, 1, 0], [0, 1, 1, 1, 0, 1, 0, 1, 1, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0], [1, 1, 1, 1, 0, 1, 1,

我有地图课,如下所示:

class Map:
def _init_(self):
    self.tiles = [
        [0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 1, 0, 1, 0, 1, 1, 0],
        [0, 1, 1, 1, 0, 1, 0, 1, 1, 0],
        [0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
        [1, 1, 1, 1, 0, 1, 1, 1, 1, 0],
        [0, 1, 0, 1, 0, 0, 0, 0, 0, 0],
        [0, 1, 0, 1, 0, 1, 1, 0, 1, 0],
        [0, 0, 0, 0, 0, 1, 1, 0, 1, 0],
        [0, 1, 1, 1, 0, 0, 0, 0, 1, 0],
        [0, 0, 0, 1, 0, 1, 1, 0, 0, 0]]
def is_floor(self, x, y):
    return self.tiles[y][x] == 0
from tkinter import *
from Hero import Hero
from map import Map

IMG_SIZE = 72
WIDTH = 10 * IMG_SIZE
HEIGHT = 10 * IMG_SIZE

root = Tk()
root.title('Wanderer Game')
canvas = Canvas(root, width=WIDTH, height=HEIGHT)
canvas.pack()

hero = Hero()
game_map = Map()

def draw_screen():
    canvas.delete("all")
    for i in range(len(game_map.tiles)): # error on here
        for j in range(len(game_map.tiles[i])):
            if game_map.tiles[i][j] == 0:
                image = root.floor
            else:
                image = root.wall
            canvas.create_image(j * 72, i * 72, anchor=NW, image=image)
主文件如下:

class Map:
def _init_(self):
    self.tiles = [
        [0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
        [0, 0, 0, 1, 0, 1, 0, 1, 1, 0],
        [0, 1, 1, 1, 0, 1, 0, 1, 1, 0],
        [0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
        [1, 1, 1, 1, 0, 1, 1, 1, 1, 0],
        [0, 1, 0, 1, 0, 0, 0, 0, 0, 0],
        [0, 1, 0, 1, 0, 1, 1, 0, 1, 0],
        [0, 0, 0, 0, 0, 1, 1, 0, 1, 0],
        [0, 1, 1, 1, 0, 0, 0, 0, 1, 0],
        [0, 0, 0, 1, 0, 1, 1, 0, 0, 0]]
def is_floor(self, x, y):
    return self.tiles[y][x] == 0
from tkinter import *
from Hero import Hero
from map import Map

IMG_SIZE = 72
WIDTH = 10 * IMG_SIZE
HEIGHT = 10 * IMG_SIZE

root = Tk()
root.title('Wanderer Game')
canvas = Canvas(root, width=WIDTH, height=HEIGHT)
canvas.pack()

hero = Hero()
game_map = Map()

def draw_screen():
    canvas.delete("all")
    for i in range(len(game_map.tiles)): # error on here
        for j in range(len(game_map.tiles[i])):
            if game_map.tiles[i][j] == 0:
                image = root.floor
            else:
                image = root.wall
            canvas.create_image(j * 72, i * 72, anchor=NW, image=image)
运行上述代码会生成一个错误:

AttributeError:“Map”对象没有属性“tiles”


代码实际上在其他系统上运行得很好,所以我想知道是不是python版本导致了错误,我是python和tkinter库的新手,因此希望您能提供帮助

错误到底在哪里?在第一次参考
.tiles
?顺便说一句,它是
\uuuu init\uuuu
而不是
\uu init\uuu
,这似乎是它解决了我的问题的原因,非常感谢