2017-08-14 195 views
1

我想添加一个图像作为pygame gui中按钮的背景。我有现在创建的按钮,我只需要添加图像。我如何将图像添加到按钮?如何添加背景图片到pygame gui中的按钮?

这是我的代码

game1 = pygame.Rect(150 , 100, 200, 150) # creates a rect object 
    pygame.draw.rect(screen, [255, 100, 0], game1) # draw objects down here 

它工作正常

回答

1

你可能寻找pygame.Surface.blithttp://www.pygame.org/docs/ref/surface.html#pygame.Surface.blit

装入背景图像和无论你想的blit它。

img = pygame.image.load('thisisanimage.png') 
WhateverYourDisplayNameIs.blit(img,(x,y)) 

以防万一,你糊涂了,它看起来像你使用screen为您的显示器表面。

+0

你能帮我一个忙,给我看一个代码示例吗?@Larry –

+0

不要忘了命名你的按钮图像'button_img' https://pastebin.com/DFmKLp0s –

+0

非常感谢你,帮助批量 –