我有一个名为 deck 的列表,它有104个元素。我想创建一个for循环,它在一个简单的GUI中在画布上显示图像(只能在CodeSkulptor上运行,这是我程序的链接,在这里: http://www.codeskulptor.org/#user41_kgywoL4h56_1.py)
循环只打印第一行,我想我更新图像中心坐标的方式是我的代码错误。
if center_d[0] >= WIDTH:
center_s[1] += height
center_d[1] += height
以下整个循环,如果您需要更多上下文,请访问我上面提供的程序链接。谢谢!
def draw(canvas):
global deck, cards, WIDTH, HEIGHT
width = 70
height = 106
center_s = [41, 59]
center_d = [41, 59]
for card in deck:
canvas.draw_image(deck_img, center_s, (width, height), center_d, (width, height))
center_s[0] += 70
center_d[0] += 70
if center_d[0] >= WIDTH:
center_s[1] += height
center_d[1] += height
答案 0 :(得分:2)
您忘记了center_s[0]
和center_s[0]
坐标。他们不断成长。
你需要将它们设置为零,例如:
if center_d[0] >= WIDTH:
center_s[0] = 41
center_d[0] = 41
center_s[1] += height
center_d[1] += height