[英]Too many positional arguments for function call error
I am using visual studio code and I am practicing the book python crash course but when I run the code it give me three problem.我正在使用 Visual Studio 代码,并且正在练习 python 速成课程这本书,但是当我运行代码时,它给了我三个问题。 I made screen print to show my problem clearly我做了丝网印刷以清楚地显示我的问题
import sys
import pygame
from settings import Settings
from ship import Ship
import game_functions as gf
def run_game():
#initialize game and create a screen object.
ai_settings = Settings()
screen = pygame.display.set_mode((ai_settings.screen_width,
ai_settings.screen_height))
pygame.display.set_mode((1200, 800))
pygame.display.set_caption("Alein Invasion")
#Make a ship.
ship= Ship(screen)
#set the background color.
bgcolor=(230,230,230)
#start the main loop for the game.
while True:
gf.check_events(ship)
ship.update()
gf.update_screen(ai_settings,screen,ship)
#Redraw the screen during each pass through the loop.
screen.fill(ai_settings.bg_color)
ship.blitme()
#make the most recently drawn screen visible.
pygame.display.flip()
run_game()
Output: Output:
line 27, in <module>
run_game()
File
"c:\Users\naema\OneDrive\Desktop\python_work\alien_invasion.py",
line 18, in run_game
gf.check_events(ship)
TypeError: check_events() takes 0 positional arguments but 1 was given
PS C:\Users\naema\OneDrive\Desktop\python_work>enter code here PS C:\Users\naema\OneDrive\Desktop\python_work>在此处输入代码
Your posted output tells us, that the function check_events() doesn't take any arguments but you provided one, ship
.您发布的 output 告诉我们,function check_events() 不带任何 arguments 但您提供了一个, ship
。 From what I found online about game_functions, it should look like this:根据我在网上找到的有关 game_functions 的信息,它应该是这样的:
import sys,pygame
def check_events(ship):
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
...
Which would be in line with your current main loop.这将符合您当前的主循环。 Did you remove its argument ship
?你删除了它的论据ship
吗? This is most likely the cause of your problem.这很可能是您的问题的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.