brettcarroll has asked for the wisdom of the Perl Monks concerning the following question:

Is it possible to change the order of Tk widgets that were attached using place? I am placing a couple of images in a Frame and would like to be able to change the order of their placement, kind of like a bring forward/backward or send to back/to front option. Is this possible using place? Here is an example:
use Tk; my $mw = MainWindow->new(); $button1 = $mw->Button(-text => 'one')->place(-x=>'10', -y=>'10'); $button2 = $mw->Button(-text => 'two')->place(-x=>'15', -y=>'15'); $button2 = $mw->Button(-text => 'three')->place(-x=>'20', -y=>'20'); $mw->MainLoop;

Replies are listed 'Best First'.
Re: Help with Tk_place
by Anonymous Monk on Feb 23, 2010 at 00:13 UTC
    Tk::Buttons are Tk::Widgets
    use Tk; my $mw = MainWindow->new(); $button1 = $mw->Button(-text => 'one')->place(-x=>'10', -y=>'10'); $button2 = $mw->Button(-text => 'two')->place(-x=>'15', -y=>'15'); $button3 = $mw->Button( -text => 'three', -command => sub { $button3->lower( $button2 ); }, )->place(-x=>'20', -y=>'20'); $mw->MainLoop;
      If you don't know which widget is below the current widget, is there a magical way to figure out the next lowest widget? Otherwise lower will place the widget at the bottom of the stack (send to back) instead of as in the example which puts the widget below it's current position (send backward).
        Who cares? You can raise the widget you want on top
        hi,

         $widget->children returns the children in stacking order.


        Cheers, Christoph