简体   繁体   English

pygame窗口中的黑屏

[英]Blank(black) screen in pygame window

I am running the following code: 我正在运行以下代码:

import pygame

pygame.init()

img = pygame.image.load("Picture.jpg")

white = (255, 255, 255)

w = 900

h = 450

screen = pygame.display.set_mode((w, h))

screen.fill((white))


screen.fill((white))

screen.blit(img(0,0))

pygame.display.flip()

while True:

         for event in pygame.event.get():

                if event.type == pygame.QUIT:

                     pygame.quit()

When I run the code the pygame window opens, but it is blank(black) screen. 当我运行代码时,pygame窗口打开,但它是空白(黑屏)。 I also get the following error message: Traceback (most recent call last): 我还收到以下错误消息:追溯(最近一次呼叫过去):

File "C:/Users/Draco/OneDrive/Documents/Programming/graphics.py", line 13, in screen.blit(img(0,0)) TypeError: 'pygame.Surface' object is not callable screen.blit(img(0,0))中的文件“ C:/Users/Draco/OneDrive/Documents/Programming/graphics.py”,第13行,TypeError:“ pygame.Surface”对象不可调用

The image I am trying to open is saved as a JPG file. 我尝试打开的图像另存为JPG文件。 The image is saved under the name Picture. 该图像被保存为图片名称。 Many thanks in advance for any help. 非常感谢您的任何帮助。

Well, Christian Dean has already answered it. 好吧,克里斯汀·迪恩已经回答了。 the syntax for pygame.blit() is: pygame.blit()的语法为:

pygame.Surface.blit(source, dest, area=None, special_flags = 0)

where source is a image, dest is the coordinates of the upper left corner of place where the Surface is going to be drawn (or a Rect) and area is a portion of the the Surface you want to draw. 其中source是图像, dest是要绘制Surface(或Rect)的位置的左上角的坐标,而area是要绘制的Surface的一部分。

The error you made is that you tried to pass the dest to the image by treating it as a function. 您所犯的错误是您试图通过将dest作为函数传递给图像。

you have to write screen.blit(img, (0, 0)) instead. 您必须改为编写screen.blit(img, (0, 0)) I recommend you to search the syntax in the pygame website before asking questions. 我建议您在问问题之前先在pygame网站上搜索语法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM