Wallter
Wallter

Reputation: 4265

Custom pyGTK button

I would like to create a button that I can control the look of the button using pyGTK. How would I go about doing this?

I would like to be able to point to a new image for each 'state' the button is in (i.e. Pressed, mouse over, normal...etc.)

Upvotes: 2

Views: 2128

Answers (2)

Chad C
Chad C

Reputation: 21

Here's an easy way to use an image on a button. Note that there is no text given when you initialize the button (self.button1 = gtk.Button()). Adding text there would display the text instead of the image.

    self.image1 = gtk.Image()
    self.image1.set_from_file('images/home.png')
    self.image1.show()
    self.button1 = gtk.Button()
    self.button1.add(self.image1)
    self.button1.show()
    self.backupHBox.pack_start(self.button1, True, True)
    self.button1.connect("clicked", self.quit)

Upvotes: 1

Glyph
Glyph

Reputation: 31880

As described in the API documentation for gtk.Image, "If you want to receive events on the image, such as button clicks, place the image inside a gtk.EventBox, then connect to the event signals on the event box.".

You probably want to use a gtk.Image rather than a gtk.Button, since buttons require more knowledge of how the theming engine works. If you really want to use a button, you'll need to read up on gtk rc files and the APIs for manipulating them.

Upvotes: 5

Related Questions