如何解决为什么我在 pygame 中调用“screen”时总是收到“TypeError: 'module' object is not callable”?
我不确定屏幕是否有问题,但每次运行此代码时:
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()
我收到这些错误: picture of output in IDLE
请帮助我,我对此很陌生,我不确定我做错了什么。我最近重新整理了很多文件,但这是我能想到的唯一答案。
解决方法
因为你使用
pygame.rect(row*square_size,column*square_size,square_size,square_size)
代替
pygame.Rect(row*square_size,square_size)
pygame.rect
是一个模块,pygame.Rect
是一个类。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。