Python 3.x - Python Tkinter
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python 3.x - Python Tkinter相关的知识,希望对你有一定的参考价值。
我正在尝试创建一个矿工游戏,但它每次都会崩溃。你能帮助我吗?这是我的代码:
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 3.x - Python Tkinter的主要内容,如果未能解决你的问题,请参考以下文章
Python3 Tkinter基础 点击按钮退出窗体 root.quit