Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Regarding Perl/Tk

by sammy_01 (Initiate)
on Jun 26, 2013 at 08:59 UTC ( #1040733=perlquestion: print w/ replies, xml ) Need Help??
sammy_01 has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I have GUI script in perl/tk which will create a label, entry & a browser button, to select a path. later i have 3 more buttons for "run" "refersh" & "exit".

Problem statement: I want the last 3 buttons to be in a newline. I am using pack and not grid. Need help on this.

Pasting the code

#### Label & Entry creation to select the test path $frm_name = $fsdb_tab -> Frame()->pack(-side => 'left', -fill => ' +both', -anchor => 'n'); $lab = $frm_name -> Label(-text=>"TEST PATH:")->pack(-side => 'lef +t'); $ent = $frm_name -> Entry(-width=>80)->pack(-side => 'left'); $ent->focus; #GUI building for Browser push buttons $but= $frm_name -> Button( -text=>"Browse", -command =>\&browser_button, -activebackground => 'lightblue', -activeforeground => 'black', -relief => 'raised', -borderwidth =>8 )->pack(-side => 'right'); #### Button for "Run FSDB" $final_frame = $fsdb_tab -> Frame(-borderwidth => '5', -relief => +'ridge')->pack(); $run_fsdb = $final_frame -> Button( -text=>"Run FSDB", -command => \&run_fsdb, -activebackground => 'lightblue', -activeforeground => 'black', -relief => 'raised', -borderwidth => 8, -width => 10 )->pack(-side => 'left', -expand => 0); #### Button for "Refresh" $refresh_frame = $fsdb_tab -> Frame(-borderwidth => '5', -relief = +> 'ridge')->pack(); $refresh_fsdb = $refresh_frame -> Button( -text=>"Refresh", -command => \&refresh_fsdb, -activebackground => 'lightblue', -activeforeground => 'black', -relief => 'raised', -borderwidth => 8, -width => 10 )->pack(-side => 'left', -expand => 0); #### Button for "EXIT" $exit_frame = $fsdb_tab -> Frame(-borderwidth => '5', -relief => ' +ridge')->pack(); $exit_fsdb = $exit_frame -> Button( -text=>"EXIT", -command => sub { $mw->destroy; exit; }, -activebackground => 'lightblue', -activeforeground => 'black', -relief => 'raised', -borderwidth => 10, -width => 10 )->pack(-side => 'right');
Sammy..

Comment on Regarding Perl/Tk
Download Code
Replies are listed 'Best First'.
Re: Regarding Perl/Tk
by thundergnat (Deacon) on Jun 26, 2013 at 13:10 UTC

    Your problem description is rather vague. Is this what you were after?

    (By the way, it is helpful to provide a COMPLETE, RUNNABLE example of your code so people don't have to fill in the boilerplate just to look at what you are trying to do.)

    UPDATE: Er... removed spurious message code from example. Copy/paste error :/

    use strict; use warnings; use Tk; my $mw = MainWindow->new; my $fsdb_tab = $mw->Frame()->pack( -expand => 1, -fill => 'both' ) +; my $button_frame = $mw->Frame()->pack( -expand => 1, -fill => 'x' ); #### Label & Entry creation to select the test path my $frm_name = $fsdb_tab->Frame()->pack( -side => 'left', -fill => 'bo +th', -anchor => 'n' ); my $lab = $frm_name->Label( -text => "TEST PATH:" )->pack( -side => 'l +eft' ); my $ent = $frm_name->Entry( -width => 80 )->pack( -side => 'left' ); $ent->focus; #GUI building for Browser push buttons my $but = $frm_name->Button( -text => "Browse", -command => \&browser_button, -activebackground => 'lightblue', -activeforeground => 'black', -relief => 'raised', -borderwidth => 8 )->pack( -side => 'right' ); #### Button for "Run FSDB" my $final_frame = $button_frame->Frame( -borderwidth => '5', -relief => 'ridge' ) ->grid( -row => 0, -column => 0 ); my $run_fsdb = $final_frame->Button( -text => "Run FSDB", -command => \&run_fsdb, -activebackground => 'lightblue', -activeforeground => 'black', -relief => 'raised', -borderwidth => 8, -width => 10 )->pack( -side => 'left', -expand => 0 ); #### Button for "Refresh" my $refresh_frame = $button_frame->Frame( -borderwidth => '5', -relief => 'ridge' ) ->grid( -row => 0, -column => 1 ); my $refresh_fsdb = $refresh_frame->Button( -text => "Refresh", -command => \&refresh_fsdb, -activebackground => 'lightblue', -activeforeground => 'black', -relief => 'raised', -borderwidth => 8, -width => 10 )->pack( -side => 'left', -expand => 0 ); #### Button for "EXIT" my $exit_frame = $button_frame->Frame( -borderwidth => '5', -relief => 'ridge' )->grid( -row => 0, -column => 2 ); my $exit_fsdb = $exit_frame->Button( -text => "EXIT", -command => sub { $mw->destroy; exit; }, -activebackground => 'lightblue', -activeforeground => 'black', -relief => 'raised', -borderwidth => 8, -width => 10 )->pack( -side => 'right' ); MainLoop;

      Here is the complete code. Click on the "FSDB Configuration" tab.

      Here i am unable to get the 3 button's in a new line

      #!/usr/bin/perl use Tk; use Tk::Text; use Tk::BrowseEntry; use Tk::DirTree; use Tk::NoteBook; use File::Basename; my %manager_hash = ( "all" => "Sheet 2", "fsdb" => "Sheet 3", ); ###################################################################### +################## ##################################### MAIN GUI ###################### +################## ###################################################################### +################## my $mw = MainWindow->new(-title=>"FSDB And Manager Launcher"); $mw->geometry( "900x270" ); #### Creating the tabs in the GUI my $book = $mw->NoteBook()->pack( -fill=>'both', -expand=>1 ); my $select = $book->add( "Sheet 1", -label=>"Manager Selection", -crea +tecmd=>\&create_managerTab ); my $all_tab = $book->add( "Sheet 2", -label=>"All configuration", -cre +atecmd=>\&getAllTab, -state=> 'normal' ); my $fsdb_tab = $book->add( "Sheet 3", -label=>"FSDB configuration", -c +reatecmd=>\&getMainTab, -state=>'normal' ); MainLoop; ###################################################################### +################## ##################################### GUI Functions ################## +################## ###################################################################### +################## sub create_managerTab { #### Radio buttons for Manager selection $frm_manager = $select -> Frame(-borderwidth => '3', -relief => 'r +idge') ->pack(); $lbl_manager = $frm_manager-> Label(-text=>"SELECT THE MANAGER'S T +O RUN: ")->pack(-side => 'left'); $manager = "all"; $rd_all = $frm_manager -> Radiobutton(-text=>"All", -value=>"all", -variable=>\$manager)->pack(-side => 'left' +, -expand => 'y'); $rd_fsdb = $frm_manager -> Radiobutton(-text=>"FSDB", -value=>"fsdb", -variable=>\$manager)->pack(-side => 'left +', -expand => 'y'); $select->Button( -text=>'OK', -command=>\&enableTab, -font => 'Times 12', -activebackground => 'lightblue', -activeforeground => 'black', -relief => 'raised', -width => 20, -borderwidth => 5)->pack(); $select->Button( -text=>'Exit', -command=>sub { $mw->destroy; exit; }, -font => 'Times 12', -activebackground => 'lightblue', -activeforeground => 'black', -relief => 'raised', -width => 20, -borderwidth => 5 )->pack(); } ################################################################# # This function is used to enable/popup the perticluar tab # # selected in the "Manager selection" tab # ################################################################# sub enableTab { print "MANAGER ===> $manager\n"; $book->raise("$manager_hash{$manager}"); } sub getMainTab { #### Label & Entry creation to select the test path $frm_name = $fsdb_tab -> Frame()->pack(-side => 'left', -fill => ' +both', -anchor => 'n'); $lab = $frm_name -> Label(-text=>"TEST PATH:")->pack(-side => 'lef +t'); $ent = $frm_name -> Entry(-width=>80)->pack(-side => 'left'); $ent->focus; #GUI building for Browser push buttons $but= $frm_name -> Button( -text=>"Browse", -command =>\&browser_button, -activebackground => 'lightblue', -activeforeground => 'black', -relief => 'raised', -borderwidth =>8 )->pack(-side => 'right'); #### Button for "Run FSDB" $final_frame = $fsdb_tab -> Frame(-borderwidth => '5', -relief => +'ridge')->pack(); $run_fsdb = $final_frame -> Button( -text=>"Run FSDB", -command => \&run_fsdb, -activebackground => 'lightblue', -activeforeground => 'black', -relief => 'raised', -borderwidth => 8, -width => 10 )->pack(-side => 'left', -expand => 0); #### Button for "Refresh" $refresh_frame = $fsdb_tab -> Frame(-borderwidth => '5', -relief = +> 'ridge')->pack(); $refresh_fsdb = $refresh_frame -> Button( -text=>"Refresh", -command => \&refresh_fsdb, -activebackground => 'lightblue', -activeforeground => 'black', -relief => 'raised', -borderwidth => 8, -width => 10 )->pack(-side => 'left', -expand => 0); #### Button for "EXIT" $exit_frame = $fsdb_tab -> Frame(-borderwidth => '5', -relief => ' +ridge')->pack(); $exit_fsdb = $exit_frame -> Button( -text=>"EXIT", -command => sub { $mw->destroy; exit; }, -activebackground => 'lightblue', -activeforeground => 'black', -relief => 'raised', -borderwidth => 10, -width => 10 )->pack(-side => 'right'); }
      Sammy..
        The technique thundergnat demonstrated is to use a container widget(Frame) with a grid sizer (or whatever), so just copy/paste that and you're good to go

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2015-07-31 06:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls