Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Stretchy grids in Tk

by rinceWind (Monsignor)
on Sep 15, 2003 at 12:18 UTC ( [id://291540]=perlquestion: print w/replies, xml ) Need Help??

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

I have an existing Tk app that works pretty well. It's actually the process monitor described in some other nodes on PM. It has a main window with buttons that change colour as processes change state.

A coworker has suggested an improvement, whereby resizing the main window would cause every button to be resized proportionally. This would be useful, in that the monitor could be maximised to fill the screen, and visible from a distance through the computer room glass window.

When I try this with the existing application, the main window does resize when you drag a corner, but all this does is to make a large amount of space surrounding the buttons.

I've not discovered how to do this with the grid geometry manager. Is it possible? Do I need to use a different geometry manager? If so, which one would be best for this application?

--
I'm Not Just Another Perl Hacker

Replies are listed 'Best First'.
Re: Stretchy grids in Tk
by Abigail-II (Bishop) on Sep 15, 2003 at 12:56 UTC
    $widget -> grid ($button1, $button2, $button3, -sticky => 'nesw');

    Abigail

      I am using -sticky => 'nsew' already. This has the effect of making each button fill the grid cell properly, but the cells are not resized wheh the master is resized.

      For an example, try the calculator example here

      Update: Have updated the calculator example to include the method suggested by herveus, which works.

      --
      I'm Not Just Another Perl Hacker

        Howdy!

        Mastering Perl/Tk, p. 47, says:

        If you use -sticky with your widgets and then resize the window, you'll notice that the widgets don't resize as you would expect. This is because resizing of the cells and the widgets in them is taken car of with the gridColumnconfigure and gridRowconfigure methods...

        Further reading suggests applying a weight of 1 to each row and column. That will allow each to expand. A row/ column with a weight of 0 takes only as much space as it needs; a weight of 2 would take twice as much space as a weight of 1 (so some can be greedier than others).

        yours,
        Michael

Re: Stretchy grids in Tk
by Molt (Chaplain) on Sep 15, 2003 at 12:57 UTC

    I don't have Tk on this machine to test this with, but you may want to try creating your widgets with -expand => 1 to expand the allocation rectangle to fill all the unfilled space, and -fill => 'both' to make the widget take up the full space of the allocation rectangle.

    Let me know if there's any problems with this as I'll have my normal Tk-equipped machine again soon so could Play.

      I don't have Tk on this machine to test this with, but you may want to try creating your widgets with -expand => 1 to expand the allocation rectangle to fill all the unfilled space, and -fill => 'both' to make the widget take up the full space of the allocation rectangle.

      That's only for the pack manager, not for the grid manager. For the latter, you need to use the -sticky option, and set it to the value nesw.

      Abigail

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-25 12:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found