Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl/Tk - positioning buttons in row

Status
Not open for further replies.

MoshiachNow

IS-IT--Management
Feb 6, 2002
1,851
IL
HI,

I seem to fail to find a way to position 3 buttons in one row,at the bottom of the text.Will appreciate help.Thanks

my $mw = new MainWindow; # Main Window
$mw->geometry('+350+10');
my $frm_name = $mw -> Frame() -> pack();
my $lab1 = $frm_name -> Label(-text=>"Enter the remote hostname or IP:") -> pack();
my $ent1 = $frm_name -> Entry() -> pack();
my $lab2 = $frm_name -> Label(-text=>"Enter the number of iterations to run [5]:") -> pack();
my $ent2 = $frm_name -> Entry() -> pack();
my $txt = $mw -> Text(-width=>90, -height=>20) -> pack(); #Text Area

my $but1 = $mw -> Button(-text=>"Start nettest", -command =>\&start)-> pack(); #Start button
my $but2 = $mw -> Button(-text=>"Stop nettest", -command =>\&KILL_MON)-> pack(); #Stop button
my $but3 = $mw -> Button(-text=>"QUIT", -command =>sub{\&KILL_MON;unlink $FILE1;$mw->destroy})-> pack(); #Quit button


Long live king Moshiach !
 
Try packing the buttons to the left.

Code:
->pack (-side => 'left');

I usually would give the buttons their own frame (frames tend to organize things better than putting things directly on the MainWindow, but it's an extra step if just packing them to the left would work too, so try that first).
 
The pack method has to be passed -side => 'left' in order for the buttons to line up side by side. But the buttons will also cling to the left side of the main window. If you want the buttons to be in the exact center, you have to create a new frame, anchor it in the center, and the pack the buttons inside the frame. Like so:
Code:
use Tk;
my $mw = MainWindow->new;          # Main Window
$mw->geometry('+350+10');
my $frm_name = $mw -> Frame() -> pack();
my $frm_button_holder = $mw->Frame()->pack(-side =>'bottom', -anchor => 'center'); # create new frame
my $lab1 = $frm_name -> Label(-text=>"Enter the remote hostname or IP:") -> pack();
my $ent1 = $frm_name -> Entry() -> pack();
my $lab2 = $frm_name -> Label(-text=>"Enter the number of iterations to run [5]:") -> pack();
my $ent2 = $frm_name -> Entry() -> pack();
my $txt = $mw -> Text(-width=>90, -height=>20) -> pack();                                                     #Text Area

my $but1 = $frm_button_holder -> Button(-text=>"Start nettest", -command =>\&start)-> pack(-side => 'left');                                 #pack button in frame with side left
my $but2 = $frm_button_holder -> Button(-text=>"Stop nettest", -command =>\&KILL_MON)-> pack(-side => 'left');                             #pack button in frame with side left
my $but3 = $frm_button_holder -> Button(-text=>"QUIT", -command =>sub{\&KILL_MON;unlink $FILE1;$mw->destroy})-> pack(-side => 'left');    #pack button in frame with side left
MainLoop;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top