PHP GTK按钮点击

发布于 2024-09-24 14:54:56 字数 870 浏览 1 评论 0原文

我试图让这个按钮改变背景你点击它,这就是我所拥有的:

<?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();
?>

< strong>为什么这不起作用?

我认为$btn->clicked(function(){部分是问题所在。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娜些时光,永不杰束 2024-10-01 14:54:56

$btn->clicked 实际上发出点击信号。您想要做的是将函数连接到信号:

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

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

$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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文