【问题标题】:How to add a background image to a button in pygame gui?如何将背景图像添加到 pygame gui 中的按钮?
【发布时间】:2017-08-14 01:30:07
【问题描述】:

我正在尝试在 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

效果很好

【问题讨论】:

    标签: user-interface button background pygame


    【解决方案1】:

    您可能正在寻找pygame.Surface.blit (http://www.pygame.org/docs/ref/surface.html#pygame.Surface.blit)

    加载您的背景图片并将其粘贴到您想要的任何位置。

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

    以防万一您感到困惑,您似乎正在使用 screen 作为您的显示界面。

    【讨论】:

    • 你能帮我一个忙,给我看一个代码示例吗?@Larry
    • 别忘了给你的按钮图片命名button_imgpastebin.com/DFmKLp0s
    • 非常感谢,帮了大忙
    猜你喜欢
    • 1970-01-01
    • 2014-07-06
    • 2019-11-11
    • 1970-01-01
    • 2011-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多