.... i don't know if its the best way..... you may want to use deeply nested hbox's and vbox's , which are created with a size_request....but see how i slide the horses in Gtk2 ....needs thread testing on a multi-threaded computer you use
$widget->set_child_packing ($child, $expand, $fill, $padding, $pack_t +ype)
it's in perldoc Gtk2::Box ...... also check out perldoc Gtk2::Widget..... it has many methods that almost all widgets inherhit ...... the way to search for methods, is read the perldoc, say perldoc Gtk2::Hbox.... at the top of the Hbox docs is the heirarchy tree..... if you don't find the method or signal in the perldoc you opened, keep going up thru the heirarchy and keep looking...... you eventually come to Gtk2::Box

... here is your code, with a nested hbox just to hold the label at pos 50..... you can get very creative with deep nesting of hbox's and vbox's

P.S. you can also use a Gtk2::Table quite imaginatively

#!/usr/bin/perl use warnings; use strict; use Gtk2 '-init'; my $window = Gtk2::Window->new; $window->set_size_request(500,400); $window->set_position('center'); $window->set_title ("Hello world"); $window->signal_connect (destroy => sub { Gtk2->main_quit; }); my $vbox = Gtk2::VBox->new(); $vbox->set("border_width"=> 10); $window->add($vbox); my $hbox1 = Gtk2::HBox->new(); $vbox->pack_start($hbox1,0,0,0); my $label = Gtk2::Label->new("hello world"); $hbox1->pack_start($label,0,0,50); # expand?, fill?, padding my $entry = Gtk2::Entry->new(); $vbox->pack_start($entry,0,0,5); my $button = Gtk2::Widget->new("Gtk2::Button", label=>"exit"); $button->signal_connect(clicked=>\&my_quit); $vbox->pack_start($button, 0,0,5); $window->show_all(); Gtk2->main; sub my_quit { print "bye!\n"; exit; }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku

In reply to Re: gtk2 widgets positions by zentara
in thread gtk2 widgets positions by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.