2017-08-14 53 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

非常感謝你,幫助批量 –