[英]why do I keep getting “TypeError: 'module' object is not callable” when calling 'screen' in pygame?
我不确定屏幕是否是问题,但每次我运行这段代码时:
import pygame
import engine
import sys
# screen config
height = 500
width = 500
dimension = 8 #dimension of an 8x8 chess board
square_size = height//dimension
FPS = 30
#pygame settings
pygame.init()
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('Tapton Chess Club')
clock = pygame.time.Clock()
screen.fill(pygame.Color("white"))
board_format = engine.game_logic()
def draw_board(screen, board_format):
draw_squares(screen)
#draw squares on screen using 2d array
def draw_squares(screen):
square_colours = [pygame.Color("#e8ebef"), pygame.Color("#7d8796")]
for row in range(dimension):
for column in range(dimension):
sq_colour = square_colours[((row+column)%2)] #used to find the colour of the square
pygame.draw.rect(screen, sq_colour, pygame.rect(row*square_size, column*square_size, square_size, square_size))
#pygame event loop to register user input
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
draw_board(screen, board_format)
clock.tick(FPS)
pygame.display.flip()
我收到这些错误: IDLE 中 output 的图片
请帮助我,我对此很陌生,我不确定我做错了什么。 我最近重新排列了很多文件,但这是我能想到的唯一答案。
因为你用
pygame.rect(row*square_size, column*square_size, square_size, square_size)
代替
pygame.Rect(row*square_size, column*square_size, square_size, square_size)
pygame.rect
是一个模块, pygame.Rect
是一个 class。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.