Python Forum
builtins.ValueError: sequence size mismatch
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
builtins.ValueError: sequence size mismatch
#1
As a beginner I wrote a simple code to draw some shapes on the screen. When I runned it I got a Fatal Python error (pygame parachute) Segmentation Fault.
I could isolate the problem to calling a pixelArray of one pixel. When I run this simplified code I get a File ..., line 9, in <module> pixArray[480][380] = BLACK builtins.ValueError: sequence size mismatch

import pygame, sys
from pygame.locals import *
pygame.init()
BLACK=[0,0,0]
WHITE=[255,255,255]
windowSurface = pygame.display.set_mode((500,400),0,32)
windowSurface.fill(WHITE)
pixArray = pygame.PixelArray(windowSurface)
pixArray[480][380] = BLACK
del pixArray
pygame.display.update()
while True:
    for event in pygame.event.get():  
        if event.type == QUIT:
            pygame.quit()  
            sys.exit()
What does this mean? What is going wrong?
Reply
#2
1. Let pygame choose best depth.
windowSurface = pygame.display.set_mode((500,400))
2. PixelArrays are like NumPy Arrays
pixArray[480, 380] = pygame.Color('Black')

3. pygame.display.update() belongs in main loop.
while True:
    for event in pygame.event.get():  
        if event.type == QUIT:
            pygame.quit()  
            sys.exit()

    pygame.display.update()
99 percent of computer problems exists between chair and keyboard.
Reply
#3
Thanks !
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020