我确实运行了代码,突然消失了,我遇到了这个错误,该怎么办?我该如何为背景图像选择合适的尺寸?
我确实运行了我的代码,但突然消失了,我遇到了一个错误,说“ screat.fill(background_img)typeerror:无效的颜色参数” 在此处输入图像描述。 我也不知道如何调整我要用于屏幕背景的背景图像的大小
pygame.init()
background_img = pygame.image.load("C:\\Users\\lenovo\\Pictures\\maxresdefault.jpg")
(width, height) = (800, 800)
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('Hop Along')
screen.fill(background_img)
pygame.display.update()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
I do run my code, but its suddenly gone, and I get this error saying "screen.fill(background_img)TypeError: invalid color argument"enter image description here.
I dont also know how to resize the background image that i want to use for my screen background
pygame.init()
background_img = pygame.image.load("C:\\Users\\lenovo\\Pictures\\maxresdefault.jpg")
(width, height) = (800, 800)
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('Hop Along')
screen.fill(background_img)
pygame.display.update()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能带有图像的显示。您必须图像:
screen.fill(backgrough_img)
如果背景图像的大小与窗口不同,则可以使用
You cannot
fill
the display with an image. You mustblit
an image:screen.fill(background_img)
If the background image is a different size than the window, you can use
pygame.transform.smoothscale
to scale the image: