![](/img/trans.png)
[英]Why my background image is not appearing in the window in pygame?
[英]Using a background image in pygame window
我有一个简单的python文件,可打开pygame
窗口。 当我单击并在窗口内释放时,程序将告诉我开始单击时光标所在的位置以及释放位置。 如何在pygame
窗口中包含具有背景图像的代码? 到目前为止,我仅以独立的方式执行此程序。
import pygame, sys
LEFT = 1
running = True
screen = pygame.display.set_mode((1200, 1000))
while running:
screen.fill((0,0,0))
pygame.display.flip()
event = pygame.event.poll()
if event.type == pygame.QUIT:
running = False
pygame.quit()
elif event.type == pygame.MOUSEBUTTONDOWN and event.button == LEFT:
print ("You pressed the left mouse button at (%d, %d)" % event.pos)
elif event.type == pygame.MOUSEBUTTONUP and event.button == LEFT:
print ("You released the left mouse button at (%d, %d)" % event.pos)
您可以使用以下行加载图像:
my_image = pygame.image.load('my_image.png')
然后使用以下行将其显示在屏幕上:
screen.blit(my_image, (x, y)) # screen = pygame.display.set_mode((1200, 1000))
还请注意,x和y表示照片左上角的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.