|
Posted by Graham Feeley on July 31, 2008, 7:26 pm
Please log in for more thread options
Hi I am a Newbie and trying to get a menu to work.
I have place 3 buttons so far on a form, however I would like to know how to
place them where I want them.
EG: on this form I would like the buttons to be on the bottom of the form
and in one row????
Any help would be appreciative!!
------------------
#!/usr/bin/perl -w
# Display Hello World program
use diagnostics;
use Tk;
use strict;
use warnings;
my $font1 = "arial 10 bold";
my $font2 = "courier 12 bold";
my $mw = MainWindow->new;
$mw->geometry("1024x512");
$mw->title("GUI Test");
my $frame1 = $mw->Frame(-width=>1024,
-height=>128,
-relief=>"raised")->grid();
my $btn1 = $mw->Button(-text=>"Exit",
-font=>$font2,
-width=>9, # width of the button in screen
units
-height=>3, # height of the button in screen
units
-relief=>"raised", # raised solid ridge sunken flat
groove
-state=>"normal", # normal active or disabled
-command =>sub)
->grid( -pady=>10);
my $btn2 = $mw->Button(-text=>"Btn2",
-font=>$font2,
-width=>9, # width of the button in screen units
-height=>3, # height of the button in screen units
-relief=>"raised", # raised solid ridge sunken flat groove
-state=>"normal", # normal active or disabled
-command =>sub)
->grid( -pady=>10);
my $btn3 = $mw->Button(-text=>"Btn3",
-font=>$font2,
-width=>9, # width of the button in screen units
-height=>3, # height of the button in screen units
-relief=>"raised", # raised solid ridge sunken flat groove
-state=>"normal", # normal active or disabled
-command =>sub)
->grid( -pady=>10);
MainLoop;
|
|
Posted by Ben Morrow on July 31, 2008, 8:26 pm
Please log in for more thread options
> Hi I am a Newbie and trying to get a menu to work.
> I have place 3 buttons so far on a form, however I would like to know how to
> place them where I want them.
> EG: on this form I would like the buttons to be on the bottom of the form
> and in one row????
I generally find it easier to use the 'pack' geometry manager than
'grid'. You also really need to sort out your indentation, and use
variables and loops to avoid saying the same thing over and over.
Something like this should get you started:
#!/usr/bin/perl -w
# Display Hello World program
use diagnostics;
use Tk;
use strict;
use warnings;
my $font2 = "courier 12 bold";
my $mw = MainWindow->new;
$mw->geometry("1024x512");
$mw->title("GUI Test");
my @BTN = (
-font=>$font2,
-width=>9, # width of the button in screen units
-height=>3, # height of the button in screen units
-relief=>"raised", # raised solid ridge sunken flat groove
-state=>"normal", # normal active or disabled
);
my @btns = (
[ Exit => sub { exit } ],
[ Btn2 => sub { exit } ],
[ Btn3 => sub { exit } ],
);
for (@btns) {
my ($txt, $sub) = @$_;
$mw->Button(
@BTN,
-text => $txt,
-command => $sub,
)->pack(
-side => 'left',
-padx => 10,
-pady => 10,
-anchor => 's',
);
}
MainLoop;
__END__
Ben
--
I touch the fire and it freezes me, [ben@morrow.me.uk]
I look into it and it's black.
Why can't I feel? My skin should crack and peel---
I want the fire back... BtVS, 'Once More With Feeling'
|
|
Posted by zentara on August 1, 2008, 7:48 am
Please log in for more thread options On Fri, 1 Aug 2008 09:26:28 +1000, "Graham Feeley"
>Hi I am a Newbie and trying to get a menu to work.
>I have place 3 buttons so far on a form, however I would like to know how to
>place them where I want them.
>EG: on this form I would like the buttons to be on the bottom of the form
>and in one row????
>Any help would be appreciative!!
As Ben Morrow said, pack is usually preferred because it resizes
nicely. Get in the habit of making separate frames and using the
-expand and -fill options. You can have frames nested in frames
for very complex packing behavior.
This is how I would do it, make a top and bottom frame, but only
let the topframe expand in the y direction. Make the buttons uniform,
by letting them expand, and padx them. (You don't need to specify
the -state => 'normal'....it's normal by default.)
#!/usr/bin/perl -w
# Display Hello World program
use diagnostics;
use Tk;
use strict;
use warnings;
my $font1 = "arial 10 bold";
my $font2 = "courier 12 bold";
my $mw = MainWindow->new;
$mw->geometry( "600x400" );
$mw->title( "GUI Test" );
my $tframe = $mw->Frame(
-relief => "raised"
)->pack(-fill=>'both',-expand => 1);
my $bframe = $mw->Frame(
-relief => "raised"
)->pack(-fill=>'x',-expand =>0);
my $text = $tframe->Text()
->pack(-fill=>'both',-expand => 1);
my $btn1 = $bframe->Button(
-text => "Exit",
-font => $font2,
-relief => "raised",
-command => sub { exit }
)->pack(-side => 'left', -fill=>'x',
-expand => 1, -pady => 5, -padx => 10 );
my $btn2 = $bframe->Button(
-text => "Btn2",
-font => $font2,
-relief => "raised",
-command => sub { exit }
)->pack(-side => 'left', -fill=>'x',
-expand => 1, -pady => 5, -padx => 10 );
my $btn3 = $bframe->Button(
-text => "Btn3",
-font => $font2,
-relief => "raised",
-command => sub { exit }
)->pack(-side => 'left', -fill=>'x',
-expand => 1,-pady => 5 , -padx => 10 );
MainLoop;
__END__
zentara
--
I'm not really a human, but I play one on earth.
http://zentara.net/Remember_How_Lucky_You_Are.html
|
|
Posted by Graham Feeley on August 1, 2008, 9:20 pm
Please log in for more thread options Thanx for the replies guys.
Whenever I get help like this I praise the internet forumsand you guys whom
are just great.
I am working on these forms
Regards
Graham
> Hi I am a Newbie and trying to get a menu to work.
> I have place 3 buttons so far on a form, however I would like to know how
> to place them where I want them.
> EG: on this form I would like the buttons to be on the bottom of the form
> and in one row????
> Any help would be appreciative!!
> ------------------
> #!/usr/bin/perl -w
> # Display Hello World program
> use diagnostics;
> use Tk;
> use strict;
> use warnings;
> my $font1 = "arial 10 bold";
> my $font2 = "courier 12 bold";
>
> my $mw = MainWindow->new;
> $mw->geometry("1024x512");
> $mw->title("GUI Test");
>
> my $frame1 = $mw->Frame(-width=>1024,
> -height=>128,
> -relief=>"raised")->grid();
>
> my $btn1 = $mw->Button(-text=>"Exit",
> -font=>$font2,
> -width=>9, # width of the button in screen
> units
> -height=>3, # height of the button in screen
> units
> -relief=>"raised", # raised solid ridge sunken flat
> groove
> -state=>"normal", # normal active or disabled
> -command =>sub)
> ->grid( -pady=>10);
>
> my $btn2 = $mw->Button(-text=>"Btn2",
> -font=>$font2,
> -width=>9, # width of the button in screen units
> -height=>3, # height of the button in screen
> units
> -relief=>"raised", # raised solid ridge sunken flat
> groove
> -state=>"normal", # normal active or disabled
> -command =>sub)
> ->grid( -pady=>10);
> my $btn3 = $mw->Button(-text=>"Btn3",
> -font=>$font2,
> -width=>9, # width of the button in screen units
> -height=>3, # height of the button in screen
> units
> -relief=>"raised", # raised solid ridge sunken flat
> groove
> -state=>"normal", # normal active or disabled
> -command =>sub)
> ->grid( -pady=>10);
>
> MainLoop;
>
>
|
| Similar Threads | Posted | | CGI.pm Button Generation | February 6, 2007, 8:21 pm |
| Redirect on the NO pushing button | March 31, 2005, 10:17 pm |
| basic cgi button question | August 14, 2005, 1:40 pm |
| How to set value to radio button with mechanze.pl | June 20, 2007, 10:39 am |
| handle multiple submit button. | December 28, 2004, 5:40 pm |
| Index Value of a Button Widget in Perl/Tk | March 14, 2007, 6:23 pm |
| Compose a outlook mail with voting button | April 17, 2005, 8:56 am |
| one submit button to call cgi script and process link in another form | March 20, 2006, 11:07 pm |
| How to show 'expiry page' when user click 'back' button in browser ? | October 14, 2004, 10:45 am |
| HTTP::Request::Form - Can't submit a form with input type=image button | January 31, 2005, 11:42 pm |
|