Python 3.x - Python Tkinter

问题描述 投票:-3回答:1

我正在尝试创建一个矿工游戏,但它每次都会崩溃。你能帮助我吗?这是我的代码:

def refill(event):
    for i in everything:
        c.delete(i) # This is the 'Delete' statement
        time.sleep(0.01)
        global x2
        global y2
        for i in range(10): # This is the 'Create' statement
            for i in range(10):
                if random.randint(1, IRON_CHANCE) != 1:
                    stone = c.create_rectangle(x2, y2, x2 + 50, y2 + 50, fill='dim gray')
                    everything.append(stone)
                    y2 += 50
                if random.randint(1, IRON_CHANCE) == 1:
                    ironStone = c.create_rectangle(x2, y2, x2 + 50, y2 + 50, fill='dim gray')
                    ironRect = c.create_rectangle(x2 + 10, y2 + 10, x2 + 40, y2 + 40, fill='ivory')
                    irons.append(ironRect)
                    everything.append(ironStone)
                    everything.append(ironRect)
                    y2 += 50
                    time.sleep(0.01)
            x2 += 50
            y2 = 0
            time.sleep(0.01)

我认为问题出在“创建”状态。如果我删除该状态,游戏将顺利无误地运行。你能帮我么?

python tkinter crash
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.