Re: How to Add a Label??
| From: | Rich Payne | Date: | Fri, 19 Jul 2002 13:09:31 +0000 |
| Subject: | Re: How to Add a Label?? | ||
| References: | 1 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-2270@lists.php.net to get a copy of this message | ||
On Fri, 19 Jul 2002, Mark Lopus wrote:
> Hi,
>
> I'm still grappling with some conceptual issues...if you have any advise, pls. advise.
>
> In the following, I want to add a label to the window whent he button is
> clicked, but When we click the button, the application quits! Why is
> this and what's the right way to do it? Thx in advance! <?php
>
> dl('php_gtk.' . (strstr(PHP_OS, 'WIN') ? 'dll' :
> 'so'));
>
> function show_label($window,$box)
> {
> $label = &new GtkLabel("I'm the label text");
> $box->add($label);
> $box->show_all();
> $window->show_all();
> }
>
> $window = &new GtkWindow(GTK_WINDOW_DIALOG);
> $window->set_default_size(400,300);
> $window->connect_object('destroy', array('gtk', 'main_quit'));
> $window->realize();
>
> $vbox = &new GtkVBox();
> $window->add($vbox);
>
> $hbuttonbox = &new GtkHButtonBox();
> $vbox->pack_start($hbuttonbox);
>
> $button1 = &new GtkButton("Add Label");
> $hbuttonbox->pack_start($button1);
> $button1->connect_object("clicked","show_label",$window,$hbox1);
There's two things I would change. First you need to create
the object first, notice how you passed it to the function before creating
it. Second it should really look like this:
$button1->connect_object("clicked","show_label",&$window,&$hbox1);
Notice the addition of the '&' before the variables. This says to pass a
pointer to the object instead of passing a copy of the object. Trust me,
this will make life much easier down the road.
One handy thing in php is the var_dump call. You can call it on any object
and it will tell you what that object is. So for example in your original
code if you did a:
var_dump($box);
just inside the show_label function you would see that it is NULL, instead
of being an object of type GtkHBox.
--rdp
--
Rich Payne
http://talisman.mv.com