简体   繁体   English

“类型错误:元组索引必须是整数或切片,而不是元组”是什么意思?

[英]what does it mean by 'TypeError: tuple indices must be integers or slices, not tuple'?

import pygame
import time
import random

# pygame window initialisation
pygame.init()

#declare the colors using their RBG colors
orangecolor = (253, 123, 7)
blackcolor = (0, 0, 0)
redcolor = (213, 50 , 80)
greencolor = (0, 255, 0)
bluecolor = (50, 153, 213)

#Dislay window's width and height
display_width = 600
display_height = 600
dis = pygame.display.set_mode((display_width, display_height))
pygame.display.set_caption("Snake Game")
snake_block = 10
game_over = False
while not game_over:
    for event in pygame.event.get():
        if event.type == quit:
            game_over = True
    pygame.draw.rect(dis,orangecolor[200,150,snake_block, snake_block])
pygame.display.update()
pygame.quit()

the terminal displays an error for the line pygame.draw.rect(dis,orangecolor[200,150,snake_block, snake_block]) is there any error in the code?终端显示pygame.draw.rect(dis,orangecolor[200,150,snake_block, snake_block])错误代码中是否有任何错误? I use visual studio 2019 community version我用的是visual studio 2019社区版

It is a typo.这是一个错字。 There is missing a , after orangecolor :orangecolor之后缺少一个,

pygame.draw.rect(dis,orangecolor[200,150,snake_block, snake_block])

pygame.draw.rect(dis, orangecolor, [200, 150, snake_block, snake_block])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:列表索引必须是整数或切片,而不是元组? - TypeError: list indices must be integers or slices, not tuple? TypeError 元组索引必须是整数或切片而不是日期时间 - TypeError tuple indices must be integers or slices not datetime TypeError:范围索引必须是整数或切片,而不是元组 - TypeError: range indices must be integers or slices, not tuple 类型错误:元组索引必须是整数或切片,而不是 dict - TypeError: tuple indices must be integers or slices, not dict 类型错误:元组索引必须是整数或切片,而不是 str - TypeError: tuple indices must be integers or slices, not str TypeError:列表索引必须是整数或切片,而不是元组 - TypeError: list indices must be integers or slices, not tuple Python TypeError:元组索引必须是整数或切片,而不是元组? - Python TypeError: Tuple indices must be integers or slices, not tuple? 元组索引必须是整数或切片,而不是元组 - tuple indices must be integers or slices, not tuple 类型错误:列表索引必须是整数或切片,而不是在 python 中使用 sys 导入的元组 - TypeError: list indices must be integers or slices, not tuple with sys import in python 如何解决 Python 中的“TypeError:元组索引必须是整数或切片”错误? - How to solve "TypeError: tuple indices must be integers or slices" error in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM