views:

25

answers:

1

I'm trying to make this button change background when you click it and this is what I have:

<?php
if (!class_exists('gtk')) {
    die("Please load the php-gtk2 module in your php.ini\r\n");
}
function loc(){
  return dirname(__FILE__);
};
$wnd = new GtkWindow();
$wnd->set_title('Picture Viewer');
$wnd->set_resizable(false);
$wnd->set_position(GTK_WIN_POS_CENTER);
$wnd->connect_simple('destroy', array('gtk', 'main_quit'));



$im = GtkImage::new_from_file(loc()."\bg.jpg");
$btn = new GtkButton;
$btn->set_image($im);

$btn->clicked(function(){
  $im = GtkImage::new_from_file(loc()."\bg2.jpg");
  $btn->set_image($im);
});

$wnd->add($btn);

$wnd->show_all();
Gtk::main();
?>

Why doesn't this work?

I think that the $btn->clicked(function(){ part is the problem.

+3  A: 

$btn->clicked actually emits the clicked signal. What you want to do is connect a function to the signal:

$btn->connect('clicked', 'change_background');

function change_background($whichbutton)
{
    $im = GtkImage::new_from_file(loc()."\bg2.jpg");
    $whichbutton->set_image($im);
}
Karl Bielefeldt