gpt4 book ai didi

python - 收到错误消息说 super 需要 1 个参数,但给出了 0 个参数?

转载 作者:太空宇宙 更新时间:2023-11-03 17:09:46 25 4
gpt4 key购买 nike

所以我收到一个错误,说 super() 采用 1 个参数,但它想要采用什么参数???我真的不知道它在要求什么!有人可以帮我解决这个问题,或者至少告诉我出了什么问题吗?

import pygame

# Define some colors
BLACK = ( 0, 0, 0)
WHITE = ( 255, 255, 255)
GREEN = ( 0, 255, 0)
RED = ( 255, 0, 0)



class Me(pygame.sprite.Sprite):
super().__init__()
def __init__(self, color, width, height):
self.image = pygame.Surface([width, height])
self.image.fill(color)

self.rect = self.image.get_rect()


you = pygame.sprite.Group()

all_sprites_list = pygame.sprite.Group()

player = Player(GREEN, 20, 15)
all_sprites_list.add(player)
pygame.init()

# Set the width and height of the screen [width, height]
size = (800, 600)
screen = pygame.display.set_mode(size)

pygame.display.set_caption("Karl's Game")

#Loop until the user clicks the close button.
done = False

# Used to manage how fast the screen updates
clock = pygame.time.Clock()
#Loading pictures
background_image = pygame.image.load("back.jpg").convert()

#Variables
# Speed in pixels per frame
x_speed = 0
y_speed = 0

# Current position
x_coord = 10
y_coord = 10
# -------- Main Program Loop -----------
while not done:
# --- Main event loop
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
done = True # Flag that we are done so we exit this loop


elif event.type == pygame.KEYDOWN:
# Figure out if it was an arrow key. If so
# adjust speed.
if event.key == pygame.K_LEFT:
x_speed = -3
elif event.key == pygame.K_RIGHT:
x_speed = 3
if x_coord > 200:
x_speed = 0
elif event.key == pygame.K_UP:
y_speed = -3
elif event.key == pygame.K_DOWN:
y_speed = 3
elif event.type == pygame.KEYUP:
# If it is an arrow key, reset vector back to zero
if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
x_speed = 0
elif event.key == pygame.K_UP or event.key == pygame.K_DOWN:
y_speed = 0



x_coord = x_coord + x_speed
y_coord = y_coord + y_speed

player.rect.x = pos[x_coord]
player.rect.y = pos[y_coord]
# First, clear the screen to white. Don't put other drawing commands
# above this, or they will be erased with this command.


# --- Drawing code should go here
screen.blit(background_image, [0,0])
drawSquare(screen, x_coord, y_coord)

# --- Go ahead and update the screen with what we've drawn.
pygame.display.flip()

# --- Limit to 60 frames per second
clock.tick(45)

# Close the window and quit.
# If you forget this line, the program will 'hang'
# on exit if running from IDLE.
pygame.quit()

最佳答案

您必须将 super() 调用移到类 init(self): 函数中。它应该是方法旁边的第一行。

此外,应该读取 super 调用。

super(Me, self).__init__()

关于python - 收到错误消息说 super 需要 1 个参数,但给出了 0 个参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34214300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com