【问题标题】:Pygame Error: couldn't create DIB sectionPygame 错误:无法创建 DIB 部分
【发布时间】:2014-04-13 11:29:12
【问题描述】:

我刚刚从它的网站 (http://pygame.org/download.shtml) 的下载页面下载了 pygame(python 模块),我选择了名为“pygame-1.9.1.win32-py2.7.msi”的包。当我试图执行一个程序时,我得到了这个错误:

Traceback (most recent call last):
  File "C:\Users\kkkkllkk53\The Mish Mash Files\langtons ant.py", line 16, in <module>
    windowSurface = pygame.display.set_mode((window_length, window_length), 0, 32)
error: Couldn't create DIB section

我不知道这意味着什么。有人可以帮帮我吗?

我使用的是 64 位 Windows 7 hp 笔记本电脑。有问题的程序是试图可视化“Langton's Ant”,它是这样的:

import pygame, sys

black = (0, 0, 0)
white = (255, 255, 255)
red = (255, 0, 0)

colour_code = { True: red, False: white }

pygame.init()
mainClock = pygame.time.Clock()

cell_length = 10
num_cells_per_side = 10000

window_length = cell_length * num_cells_per_side
windowSurface = pygame.display.set_mode((window_length, window_length), 0, 32)
pygame.display.set_caption('Langtons ant')
windowSurface.fill(white)

def cell_2_rect(x, y):
    rect_x = ( 5000 + x ) * cell_length
    rect_y = ( 5000 + y ) * cell_length
    return pygame.Rect( rect_x, rect_y )

ant_x = 0
ant_y = 0
ant_angle = 1

angles = { 0: [1, 0], 1: [0, -1], 2: [-1, 0], 3: [0, 1] }

row = [ False ] * num_cells_per_side
matrix = [ row.copy() ] * num_cells_per_side

def turn_ant():
    turn = matrix[ant_y, ant_x]
    if turn:
        ant_angle += 1
    else:
        ant_angle -= 1
    ant_angle = ant_angle % 4

def move_ant():
    displacement = angles[ ant_angle ]
    delta_x = displacement[0]
    delta_y = displacement[1]
    ant_x += delta_x
    ant_y += delta_y

def update_square():
    cell = matrix[ant_x][ant_y]
    cell = not cell
    pygame.draw.rect( windowSurface, colour_code[cell], cell_2_rect(ant_x, ant_y) )

def show_ant():
    pygame.draw.rect( windowSurface, red, cell_2_rect(ant_x, ant_y) )

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()
    update_square()
    turn_ant()
    move_ant()
    show_ant()
    pygame.display.update()
    mainClock.tick(100)

【问题讨论】:

    标签: python pygame dib


    【解决方案1】:

    您正在尝试创建一个太大的显示:

    cell_length = 10
    num_cells_per_side = 10000
    
    window_length = cell_length * num_cells_per_side
    windowSurface = pygame.display.set_mode((window_length, window_length), 0, 32)
    

    等于:(100000,100000)

    试试(800x600)

    如果您需要一个更大的世界,您可以尝试创建一个更大的表面(而不是显示),然后只将您需要的内容传送到屏幕上。

    【讨论】:

      猜你喜欢
      • 2019-08-11
      • 2013-10-16
      • 1970-01-01
      • 1970-01-01
      • 2010-10-28
      • 2012-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多