Button Help

This is what I am currently doing to crate a button with a background image.

bImage = loader.loadTexture("Images/buildButton.jpg");
        print bImage;
        b = DirectButton(image = bImage, scale=.1, command=self.BuildButton);
        b.setPos(1.1, 0, -.75);

There seems to be many ways to use buttons. Is my method a good way of doing it? I noticed that if the scale is set to ‘1’, it is not the default size of the image. Is that because it is taking the default size of the button rather than the image? It seems that every button will need its scale set very low.

Images have no default size; they exist in texture memory, not in screen space. The button usually scales itself based on any text or card you give it, but if all you give it is a texture, it has nothing to go on.

The egg-texture-cards command can be used to create a card that is scaled appropriately based on the original size of the texture (the manual describes this a bit). You can also set the size of your button explicitly with the frameSize parameter (it receives a four-tuple: the left, right, bottom, top bounds of your button).

But if you are happy with the results you get above, I see no reason not to continue doing it that way.


the egg-texture-cards command keeps telling me that is unable to read the image even though I am positive that the path I am providing to the image is correct. I am trying to read in a .jpg or .bmp by the way. Any ideas?

Nevermind. I figured it out :slight_smile:. I had to be in the folder where the image was being read from.