即使我定义了layout_window也未定义

时间:2019-11-30 19:57:08

标签: python layout window undefined

我用python的一本编码书做了一个游戏,它说即使我写了layout_window也没有定义 def layout_window(window): 这是我的代码

import tkinter
import random
gameOver = False
score = 0
squaresToClear = 0
def play_bombdodger():
    create_bombfield(bombfield)
    window = tkinter.Tk()
    layout_window(window)
    window.mainloop
bombfield = []
def create_bombfield(bombfield):
    global squaresToClear
    for row in range(0,10):
        rowList = []
        for column in range(0,10):
            if random.randint(1,100) < 20:
                rowList.append(1)
            else:
                rowList.append(0)
                squaresToClear = squaresToClear + 1
        bombfield.append(rowList)
        printfield(bombfield)
def printfield(bombfield):
    for rowList in bombfield:
        print(rowList)
play_bombdodger()
def layout_window(window):
    for rowNumber, rowList in enumerate(bombfield):
        for columnNumber, columnEntry in enumerate(bombfield):
            if random.randint(1,100) < 25:
                square = tkinter.Label(window, text = "    ", bg = "darkgreen")

1 个答案:

答案 0 :(得分:0)

您调用play_bombdodger,后者调用layout_window,但是在定义play_bombdodget之前先调用layout_window