CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Aligning Tk grid columns

 



PapaGeek
User

Mar 14, 2014, 12:48 PM

Post #1 of 6 (3245 views)
Aligning Tk grid columns Can't Post

Here is a simplified example of the top of a menu that I need to create, all of the program logic is missing.

I want to create a radio button list with the button in the middle of the explanatory text. The text on the left will be the actual data chosen and the text on the right will be a description of what is chosen. I want the left column aligned right against the buttons and the right column aligned left against the buttons.

I’ve looked all over the web but none of the examples seem to work. A couple of my attempts are commented out in the code.


Code
use Modern::Perl '2013'; 
use Tk;

my $mw = MainWindow->new();
my $rb_value = 1;
$mw->geometry( '500x220' );
$mw->optionAdd('*font' => '-*-helvetica-bold-r-*-*-*-150-*-*-*-*-*-*'); # XLFD format
$mw->Label(-text => "Choose a reporting date")->grid("-","-");
$mw->Label(-text => "2014-03-07")->grid
($mw->Radiobutton(-text => "", -value => 1, -variable => \$rb_value),
$mw->Label(-text => "Current Date"),
-sticky => "nsew", -padx => 10, -pady => 10);

$mw->Label(-text => "2014-03-07")->grid
($mw->Radiobutton(-text => "", -value => 2, -variable => \$rb_value),
$mw->Label(-text => "Yesterday"),
-sticky => "nsew", -padx => 10, -pady => 10);

$mw->Label(-text => "Date Selector Goes Here")->grid
(my $rbs = $mw->Radiobutton(-text => "", -value => 3, -variable => \$rb_value),
$mw->Label(-text => "Selected Date"),
-sticky => "nsew", -padx => 10, -pady => 10);

#$mw->gridconfigure(-column => 0, -row => 1, -sticky => 'e');
#$mw->gridColumnconfigure(0, -sticky => 'e');

MainLoop;


All of my attempts have resulted in various error messages.


FishMonger
Veteran / Moderator

Mar 14, 2014, 1:12 PM

Post #2 of 6 (3243 views)
Re: [PapaGeek] Aligning Tk grid columns [In reply to] Can't Post

You're putting each row into a single cell/column. Try splitting it up a little and use 2 columns.


PapaGeek
User

Mar 14, 2014, 1:49 PM

Post #3 of 6 (3238 views)
Re: [FishMonger] Aligning Tk grid columns [In reply to] Can't Post

Thanks, found the alternate coding in the Perl/Tk cookbook.

I decided to use the concept of a variable $row number so it would be easier to add rows as the window is being created.

Code
use Modern::Perl '2013'; 
use Tk;

my $mw = MainWindow->new();
my $rb_value = 1;
my $row = 0;
$mw->geometry( '500x220' );
$mw->optionAdd('*font' => '-*-helvetica-bold-r-*-*-*-150-*-*-*-*-*-*'); # XLFD format
$mw->Label(-text => "Choose a reporting date")->grid(-row => $row, -columnspan => 3);
$row++;
$mw->Label(-text => "2014-03-07")->grid(-row => $row, -column => 0, -sticky => 'e');
$mw->Radiobutton(-text => "", -value => 1, -variable => \$rb_value)->grid(-row => $row, -column => 1);
$mw->Label(-text => "Current Date")->grid(-row => $row, -column => 2, -sticky => 'w');
$row++;
$mw->Label(-text => "2014-03-07")->grid(-row => $row, -column => 0, -sticky => 'e');
$mw->Radiobutton(-text => "", -value => 2, -variable => \$rb_value)->grid(-row => $row, -column => 1);
$mw->Label(-text => "Yesterday")->grid(-row => $row, -column => 2, -sticky => 'w');
$row++;
$mw->Label(-text => "Date Selector Goes Here")->grid(-row => $row, -column => 0, -sticky => 'e');
my $rbs = $mw->Radiobutton(-text => "", -value => 3, -variable => \$rb_value)->grid(-row => $row, -column => 1);
$mw->Label(-text => "Selected Date")->grid(-row => $row, -column => 2, -sticky => 'w');

MainLoop;



PapaGeek
User

Mar 16, 2014, 6:42 AM

Post #4 of 6 (3120 views)
Re: [PapaGeek] Aligning Tk grid columns [In reply to] Can't Post

Is there a way to micro-manage the spacing of grid elements?

I want to have 10 pixles between all of the various buttons, and I want 20 pixels between the grid elements and the sides of the windows.

gridRowconfigure and gridColumnconfigure allow for a –pad => 20 option, but that puts 20 pixels around everything. These methods do not accept the –sticky option to manage each side independently.

What is the best way to micro-manage the widget spacing in a grid?


FishMonger
Veteran / Moderator

Mar 16, 2014, 9:27 AM

Post #5 of 6 (3104 views)
Re: [PapaGeek] Aligning Tk grid columns [In reply to] Can't Post

Have you tried using the -ipadx and -ipady options in combination with -padx and -pady?

If that doesn't do what you want, then you may need to use the place geometry manager instead of grid.
http://search.cpan.org/~srezic/Tk-804.032/pod/place.pod

I'm going to through a curve ball at you and suggest something outside of perl.

Back in 2007/2008 our company was migrating off of Novel and I was tasked with writing a gui app to replace the novel login. To get it up and running in the shortest amount of time I used Perl/Tk, but at the time I knew it wasn't going to be secure enough and I would need to rewrite it in another language. I chose to redo it in RealBasic from Real Studio, which has changed names several times since then and is now known as Xojo.

It's a cross platform language and the same code base can be compiled for Windows, Linux, and MAC. Its IDE uses drag/drop to place the gui elements exactly where you want and you can have as many separate windows as you wish. As you build the gui layout (or after it's done) you switch to the code window and fill in the blanks so to speak.

You can download it a try it for free.
http://www.xojo.com/


PapaGeek
User

Mar 16, 2014, 11:26 AM

Post #6 of 6 (3090 views)
Re: [FishMonger] Aligning Tk grid columns [In reply to] Can't Post

The individual placement might work instead of the grid. The basic concept of the menu has a fixed design upper portion followed by a variable list of buttons which are named at the user’s discretion. The name of an account might be “Citi 401K” or “Sandy’s IRA at Charles Schwab”. I was letting the grid determine the size of my window instead of using a $window->geometry ( ‘500x200’ ); code line. In the past I’ve put that code line at the top of my code. I see no reason why I couldn’t calculate the required geometry on the fly and define the geometry at the end of the window.

Since there will be a separate maintenance window for setting up and naming accounts, I can just measure the size of the account name at that point and save it in the database along with the actual name. It might be fun to play with laying out the account buttons on the fly, with long buttons straddling multiple short buttons. Something to keep me off the streets and out of trouble. I might be a geek, but I can still be a bad boy at 66! SMILE

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives