TypeError tuple indices must be integers or slices not tuple

0 votes

Im a begginer and im trying to make a snake using pygame and i ran into this error and i dont understand this erorr

import pygame
from random import randrange


def snake_head(snx,sny,display,red):
    pygame.draw.rect(display,red,[snx,sny,49,49])

def grids():
    for x in range(12):
        for y in range(12):
            rect=pygame.Rect(x*blcsize,y*blcsize,blcsize,blcsize)
            pygame.draw.rect(display, white, rect, 1)
def mouse(x,y):
    pygame.draw.rect(display,white, [x, y, 49, 49])

def the_fucking_tail(headcordlist,tailcount,display,red):
    for x in range(tailcount):
        print(headcordlist[x][0], headcordlist[x][1])
        tailx=headcordlist[x][0]
        taily=headcordlist[x][1]
        pygame.draw.rect(display,red[tailx,taily,45,45])




pygame.init()
black=(0,0,0)
white=(250,250,250)
red=(250,0,0)
blcsize=50
sny=250
snx=250
snychange=0
snxchange=0
mouscordx=randrange(0,12)*50
mouscordy=randrange(0,12)*50
display=pygame.display.set_mode((600,600))
CLOCK = pygame.time.Clock()
pygame.display.set_caption('azhdars legacy')
icon = pygame.image.load('cobra.png')
pygame.display.set_icon(icon)

runnig=True
display.set_alpha(None)
movment='none'
tailcount=0
headcordslist=[]


while runnig:
#display
    display.fill(black)
    grids()
    mouse(mouscordx,mouscordy)
#mouse check
    if [snx,sny]==[mouscordx,mouscordy]:
        mouscordx = randrange(0, 12) * 50
        mouscordy = randrange(0, 12) * 50
        tailcount+=1
#movements
    for event in pygame.event.get():
        if event.type==pygame.QUIT:
            runnig=False
        if event .type==pygame.KEYDOWN:
            if event.key==pygame.K_RIGHT:
                if movment=='left':
                    pass
                else:
                    movment='right'
                    snxchange=50
                    snychange=0
            if event.key==pygame.K_LEFT:
                if movment =='right':
                    pass
                else:
                    movment='left'
                    snxchange =-50
                    snychange=0
            if event.key == pygame.K_UP:
                if movment=='down':
                    pass
                else:
                    movment='up'
                    snxchange =0
                    snychange =-50
            if event.key == pygame.K_DOWN:
                if movment=='up':
                    pass
                else:
                    movment='down'
                    snxchange = 0
                    snychange =50

    pygame.time.delay(300)
    snx+=snxchange
    sny+=snychange
    headcords=list([snx,sny])

    print(headcordslist)
    #print(headcords)
    headcordslist.insert(0,headcords)
    #print(headcordslist)
    headcordslist=list(headcordslist)
    if len(headcordslist)>tailcount:
        headcordslist.pop()
    the_fucking_tail(headcordslist,tailcount,display,red)


    snake_head(snx, sny, display, red)

    pygame.display.update()
Oct 19, 2020 in Python by peyman
• 120 points

edited Oct 19, 2020 by Gitika 1,125 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
3 answers
0 votes
0 answers

TypeError: tuple indices must be integers or slices, not tuple

Traceback (most recent call last):   File "main.py", line ...READ MORE

Aug 25, 2020 in Python by Peddabudi srikanth
• 120 points
4,627 views
0 votes
1 answer

i am getting this error "TypeError: tuple indices must be integers or slices, not Database"

Hi, @Shabaj, Regarding your query, I hope this ...READ MORE

answered Dec 10, 2020 in Python by Gitika
• 65,770 points
1,163 views
0 votes
1 answer

TypeError: list indices must be integers or slices, not str

Hi@akhtar, As we know that the index of ...READ MORE

answered Oct 15, 2020 in Python by MD
• 95,460 points
13,705 views
+1 vote
1 answer

Can anyone help me with this error: TypeError: list indices must be integers or slices, not str

Hi, @Varshap  It’s a TypeError, which tells us ...READ MORE

answered Nov 5, 2020 in Python by anonymous
• 65,770 points
2,359 views
0 votes
1 answer

Python error "TypeError: string indices must be integers, not str"

Hey @Dipti email_s.append(email_1["email_address"]) This is the list on ...READ MORE

answered Jul 5, 2019 in Python by Jinu
22,944 views
0 votes
3 answers

TypeError: Index(...) must be called with a collection of some kind, 'Email' was passed

It is not working because your code ...READ MORE

answered May 13, 2020 in Python by anonymous

edited May 13, 2020 by Gitika 54,045 views
0 votes
0 answers

How to remove elements from a list that may or may not be present?

In case I want to remove some ...READ MORE

Jun 27, 2019 in Python by Nisa
• 1,090 points
795 views
0 votes
0 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP