Placing an Image on a Transparent Button (for Beginners)

Return to Code Snippets

Placing an Image on a Transparent Button (for Beginners)

Postby MDAustin » Sat Oct 10, 2009 6:53 pm

Ok I am brand new to Panda and programming and was searching around on how to get an image on to a button so you just saw the image.

There were a few issues here but I guess the big one was making it that you see the image not the button. Ok here's how I did it. I know this is not useful to 99.9% of users here but for that 0.1% like me yesterday it might help.

I am presuming you are adding the button to something you already have, i.e a little program:

Code: Select all
# To get the button

from direct.gui.DirectGui import *

# I wanted to add a background image
from direct.gui.OnscreenImage import OnscreenImage

# This next one enable the transparency and is easily overlooked
# I did for an hour anyways

from pandac.PandaModules import TransparencyAttrib

#Display background image

mainmenuTitle = OnscreenImage(image = './Graphics/mainmenuTitle.png', pos = (0, 0, 0))
# As I am truly stupid I have to label my button as exactly as possible
# This part image = etc is the path to the image

mainmenuLoadGame = DirectButton(image = './Graphics/mainmenuLoadGame.png',
# This part ensure that the button is not raised up and therefore invisible

                              relief = None,

# This is the part that gets the transparency


One thing that I did do was for a while was change the button to

buttonname.reparentTo (render3d)

This just prevented me from actually clicking the button effectively.

The buttons image was just a simple photoshop job 2 layers the bottom one transparent and the top one the text.

Here's what it looks like on a kind of brushed metal effect background:

Posts: 8
Joined: Wed Sep 30, 2009 3:35 pm
Location: Birmingham, UK

Postby zhao » Tue Jan 05, 2010 11:44 pm

I found this to be very useful! Saved an hour of debugging at least! Thanks.
Posts: 225
Joined: Tue Nov 10, 2009 5:32 pm

Postby silveralex » Fri Feb 03, 2012 4:03 pm

Thx! This is useful
User avatar
Posts: 267
Joined: Tue Apr 21, 2009 1:48 pm
Location: New York, NY

Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 1 guest