Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

problems with frame widgets of tk

by gibsonca (Beadle)
on Jun 23, 2010 at 15:53 UTC ( [id://846105]=perlquestion: print w/replies, xml ) Need Help??

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

Starting from an example off the web, I want to add these two lines so that they are left justified and vertical to each other. I've missed something. Attached is the complete program - I am just curious on how to fix the "Model File" and the "Range File" widgets. I know there are other issues...

#!/usr/bin/perl -w use Tk; use strict; # ********************** # Main() # ********************** my( $entry, $filename, $output, ); my $ver = "1.0.0"; my $mw = MainWindow->new; $mw->geometry("500x600"); $mw->title("GUI 6"); my $main_menu = $mw->Menu(); $mw->configure(-menu => $main_menu); # give the user a way to exit the script my $file_menu = $main_menu->cascade(-label=>" ", -underline => 0, -tea +roff=>0); $file_menu->command(-label=>"Exit", -underline=>0, -command => sub{exi +t}); # everyone needs a little help my $help_menu = $main_menu->cascade(-label => "Help", -underline => 0, + -tearoff => 0); $help_menu->command(-label => "Version", -underline => 0, -command => sub{$mw->messageBox(-message => "Versi +on: $ver", -type => "ok")}); $help_menu->command(-label => "About Program", -underline => 0, -comma +nd => \&show_about); my $pet_info_frame = $mw->Frame()->pack(-side => "top"); $pet_info_frame->Label(-text => "View?")->pack(-side => "top"); my $chk1 = "no"; my $chk2 = "no"; my $pet1_chk = $pet_info_frame->Checkbutton(-text => "Show All", -variable => \$chk1, -onvalue => "yes", -offvalue => "no")->pack(- +side => "right"); my $pet2_chk = $pet_info_frame->Checkbutton(-text => "Show Only Differ +ences", -variable => \$chk1, -onvalue => "yes", -offvalue => "no")->pack(- +side => "right"); my $model_info = $mw->Frame()->pack(-side => "left"); $model_info->Label(-text => "Model File : ")->pack(-side => "left"); my $model_info_frame = $mw->Frame()->pack(-side => "left"); my $entry1 = $model_info_frame->Entry( -width => 60, -textvariable => \$filename )->grid( $mw->Button( -text => "...", -command => sub { $filename = $mw->getOpenFile(-title => 'File Browser'); } ), ); $model_info = $mw->Frame()->pack(-side => "left"); my $range_info = $mw->Frame()->pack(-side => "left"); $range_info->Label(-text => "Range File : ")->pack(-side => "left"); my $range_info_frame = $mw->Frame()->pack(-side => "left"); my $entry2 = $range_info_frame->Entry( -width => 60, -textvariable => \$filename )->grid( $mw->Button( -text => "...", -command => sub { $filename = $mw->getOpenFile(-title => 'File Browser'); } ), ); my $button_frame = $mw->Frame()->pack(-side => "bottom"); $button_frame->Button(-text => "Ok", -command => \&update_output)->pac +k(); #my $output_frame = $mw->Frame()->pack(-side => "bottom"); #my $output_scroll = $output_frame->Scrollbar(); #my $output_text = $output_frame->Text(-yscrollcommand => ['set', $out +put_scroll]); #$output_scroll->configure(-command => ['yview', $output_text]); #$output_scroll->pack(-side => "bottom", -expand => "no", -fill => "y" +); #$output_text->pack(); sub update_output { if ( $chk1 eq "yes" ) { $output = "$output\nShow All"; } if ( $chk2 eq "yes" ) { $output = "$output\nShow Only Differences"; +} #$output_text->delete('0.0', 'end'); #$output_text->insert("end", $output); } sub show_about { my $help_win = $mw->Toplevel; $help_win->geometry("300x50"); $help_win->title("About Program"); my $help_msg = "This help page is an example of using multiple windo +ws."; $help_win->Label(-text => $help_msg)->pack(); $help_win->Button(-text => "Ok", -command => [$help_win => 'destroy' +])->pack(); } MainLoop;

Any help appreciated. Thanks in advance.

Replies are listed 'Best First'.
Re: problems with frame widgets of tk
by bluescreen (Friar) on Jun 23, 2010 at 18:24 UTC

    I think I found your problem, you have to define a frame for each "Model File" and "Range File" lines and make them to pack to the top and fill 100% the x axis, then within the frames you add all components justified to the left

    # CREATE MODEL FILE FRAME my $model_info_frame = $mw->Frame->pack( -side => "top", -fill => 'x' +); # Label $model_info_frame->Label( -text => "Model File : " )->pack( -side => " +left" ); # Input field $model_info_frame->Entry( -width => 60, -textvariable => \$filename )->pack( -side => "left" ); # Browse files button $model_info_frame->Button( -text => "...", -command => sub { $filename = $mw->getOpenFile( -title => 'File Browser' ); } )->pack( -side => "left" ); # CREATE RANGE FILE FRAME my $range_info_frame = $mw->Frame->pack( -side => "top", -fill => 'x' +); # Label $range_info_frame->Label( -text => "Range File : " )->pack( -side => " +left" ); # Input field $range_info_frame->Entry( -width => 60, -textvariable => \$filename )->pack( -side => "left" ); # Browse files button $range_info_frame->Button( -text => "...", -command => sub { $filename = $mw->getOpenFile( -title => 'File Browser' ); } )->pack( -side => "left" );

    your code has mixed syntax like grid and pack, use grid to define layouts based on rows and columns

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://846105]
Approved by herveus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-20 02:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found