>> Can you kindly let me know how can I change the parent of any widget.
>>
[quoted text clipped - 6 lines]
>
> -mjc
>>> Can you kindly let me know how can I change the parent of any widget.
>>>
[quoted text clipped - 18 lines]
>
>Jack
I've been sleeping with the enemy lately :-) Gtk2 can do this easily.
If you really need this functionality, maybe you should switch?
There are ways with Tk. What you want to do, is store all your info from
the pages in hashes, don't rely on widgets to store your data. You can
use the notebook's raise and lower cmds to save all data on that page.
Then instead of reparenting, just rebuild new widgets with the same hash
data. Once you get the idea, it's not hard. I suppose if you had a
canvas on the notebook frame, and the user was drawing scribbles on it,
it could get tricky; but text and entry widget data is easily saved to
hashes when the info{'focus'} or raisecmd tells you a page change
occured.
But here is a Gtk2 example (ducking :-) )
#!/usr/bin/perl
use warnings;
use strict;
use Glib qw/TRUE FALSE/;
use Gtk2 '-init';
my $window = Gtk2::Window->new('toplevel');
$window ->signal_connect( 'destroy' => \&delete_event );
$window->set_border_width(10);
$window->set_size_request(300,200);
$window->set_position('center');
my $window1 = Gtk2::Window->new('toplevel');
$window1->hide_all();
my $vbox = Gtk2::VBox->new( FALSE, 6 );
$window->add($vbox);
$vbox->set_border_width(2);
my $label_w_markup = Gtk2::Label->new();
$label_w_markup->set_markup("<span background = 'black' foreground=
'green'
size=\"20000\">Label with <i>markup</i></span>");
$vbox->pack_start($label_w_markup,FALSE,FALSE,4);
my $hbox= Gtk2::HBox->new( FALSE, 6 );
$vbox->pack_end($hbox,FALSE,FALSE,0);
$hbox->set_border_width(2);
my $button = Gtk2::Button->new_from_stock('gtk-quit');
$hbox->pack_end( $button, FALSE, FALSE, 0 );
$button->signal_connect( clicked => \&delete_event );
my $button1 = Gtk2::Button->new('Reparent');
$hbox->pack_end( $button1, FALSE, FALSE, 0 );
$button1->signal_connect( clicked => \&reparent );
my $button2 = Gtk2::Button->new('Send back');
$hbox->pack_end( $button2, FALSE, FALSE, 0 );
$button2->signal_connect( clicked => \&oldparent );
$window->show_all();
Gtk2->main;
#####################################
sub reparent{
$window1->show_all();
$label_w_markup->reparent($window1);
}
sub oldparent{
$label_w_markup->reparent($vbox);
$window1->hide_all();
}
sub delete_event {
Gtk2->main_quit;
return FALSE;
}
__END__
zentara

Signature
I'm not really a human, but I play one on earth.
http://zentara.net/Remember_How_Lucky_You_Are.html
skw - 28 Aug 2008 16:51 GMT
I agree with zentara's advice regarding storing the user data edits in
a hash structure. Keeping the data independent of the gui will give
you a great deal more flexibility with your forms/widgets.
I built a form app in Tk for users in our department to track work
flow notes. The forms include a variety of notebook tabs as well as
listbox, entry, label, and text widgets all of which are used to
display and/or edit the task notes details. In order to provide the
flexibility to work with the same data in all these widgets is to
store the user data in a anonymous hash structure. The widgets can
then be linked to whatever piece of data is needed, even the same data
that some other widget also uses.
Most of the widgets are tied to the hash by setting the -textvariable=>
$hash->{myfield}. If the user clicks the save button the hash data
is updated into a database. If the user elects to view saved data, a
query pulls it from the database and populates the hash making it
immediately available to the widgets.
With the data independent of the widgets, you should be able to
display/edit the same data in any part of the application without
trying to bounce widgets from parent to parent. Save functions are
also easier to code since the data is all in one concise place. Moving
to a data independent structure will require some reworking but can
ultimately make your app much more flexible.
Hope this is helpful.
-skw