resizing control 
Author Message
 resizing control

Hi,

I am still pretty new to perltk and have some problem with how to
control the resizing behavior regarding a frame. Hope anybody can give
me some advice. I have a frame initially set to 800*600 when startup.
This frame contains two text widgets. The two text widgets do not have
the same size when startup. In addition, they dont seem to scale
propotionally when I resize the frame. How can I have some control
over the resizing behavior.(attach the test code below)

Thanks

Joe

#=cut
package test;

$test::VERSION = '0.1';

package test;

use Tk::widgets qw/Text/;
use base qw/Tk::Frame/;
use strict;

Construct Tk::Widget 'test';

#/-----------------------------------------------------------------//
#
#/-----------------------------------------------------------------//
sub ClassInit {

        $class->SUPER::ClassInit($mw);      

Quote:
}

sub Populate {

        my ($frameA,$frameA1, $frameA2) = undef;        
        $self->SUPER::Populate($args);

        # initial all the component
        $frameA = $self->Frame(relief=>'groove',borderwidth=>'1');    
        $frameA1 = $frameA->Text(-relief => 'groove');
        $frameA2 = $frameA->Text(-relief => 'groove');

        #packing all the component sequentially
        $frameA->pack(-side => 'left', -fill => 'both', -expand => 1);
        $frameA1->pack(-side => 'left', -fill => 'both', -expand => 1);
        $frameA2->pack(-side => 'left', -fill => 'both', -expand => 1);

Quote:
}

1;

package main;

use Tk;
use test;
my $mw = MainWindow->new;
$mw->geometry("800x600+0+0");
my $tw = $mw->test()->pack(-fill=>'both', -expand=>1);
MainLoop;



Tue, 22 Mar 2005 08:48:56 GMT  
 resizing control

Quote:

> I am still pretty new to perltk and have some problem with how to
> control the resizing behavior regarding a frame. Hope anybody can give
> me some advice. I have a frame initially set to 800*600 when startup.
> This frame contains two text widgets. The two text widgets do not have
> the same size when startup. In addition, they dont seem to scale
> propotionally when I resize the frame. How can I have some control
> over the resizing behavior.(attach the test code below)

Either you can use grid geometry manager instead of pack
(gridColumnconfigure(-weight => ...) could be useful in this case) or
you can resize your text widgets "manually" by handling the Configure
event (if you don't know it, read man Tk::bind and may be try to add
this line of testing outputs into your code:

Ev('h')]);
).

May be there are also some narrower way or some quite different one, I
don't know perl/tk very well.

P.



Tue, 22 Mar 2005 17:49:57 GMT  
 resizing control

Quote:


> Either you can use grid geometry manager instead of pack
> (gridColumnconfigure(-weight => ...) could be useful in this case) or
> you can resize your text widgets "manually" by handling the Configure
> event (if you don't know it, read man Tk::bind and may be try to add
> this line of testing outputs into your code:

> Ev('h')]);
> ).

Hi,

Thanks for helping. but I still have some problem to get this to work.
I need a little more advice.

If I continue to use pack method. I can use the above binding to get
the size of the main frame (unit in pixel). I assume that if I expose
some configuration method from the widget, I may be can use the
information I got from the binding to enforce the size of the
subwidget? Is this possible? Also, Text widget only have
-height/-width configuration option (unit in characters) , can I have
other way to control using the size in pixel

If I change to grid. I have a question of how to use it in the custom
widget In my code, $frameA is the toplevel rame that holds two text
widgets in my custom widget. How to set the grid parameter (-in) of
this frame?

$frameA->grid(-in => ??????? , -row => 1, -column => 1, -sticky =>
'news');

any more advice or a simple example :)

Thanks

Tun Tao Tsai



Wed, 23 Mar 2005 10:53:33 GMT  
 resizing control

Quote:


>>Either you can use grid geometry manager instead of pack
>>(gridColumnconfigure(-weight => ...) could be useful in this case) or
>>you can resize your text widgets "manually" by handling the Configure
>>event (if you don't know it, read man Tk::bind and may be try to add
>>this line of testing outputs into your code:

>>Ev('h')]);
>>).

> Thanks for helping. but I still have some problem to get this to work.
> I need a little more advice.

> If I continue to use pack method. I can use the above binding to get
> the size of the main frame (unit in pixel). I assume that if I expose
> some configuration method from the widget, I may be can use the
> information I got from the binding to enforce the size of the
> subwidget? Is this possible?

Yes, it might be possible, see below.

Quote:
> Also, Text widget only have
> -height/-width configuration option (unit in characters) , can I have
> other way to control using the size in pixel

> If I change to grid. I have a question of how to use it in the custom
> widget In my code, $frameA is the toplevel rame that holds two text
> widgets in my custom widget. How to set the grid parameter (-in) of
> this frame?

> $frameA->grid(-in => ??????? , -row => 1, -column => 1, -sticky =>
> 'news');

You needn't set -in, RTF man Tk::grid.

Quote:
> any more advice or a simple example :)

Grrr... OK :)

 > package test;
 >
 > $test::VERSION = '0.1';
 >
 > package test;
 >
 > use Tk::widgets qw/Text/;
 > use base qw/Tk::Frame/;
 > use strict;
 >
 > Construct Tk::Widget 'test';
 >
 > #/-----------------------------------------------------------------//
 > #
 > #/-----------------------------------------------------------------//
 > sub ClassInit {

 >   $class->SUPER::ClassInit($mw);      
 > }
 >
 > sub Populate {

 >   my ($frameA,$frameA1, $frameA2) = undef;        
 >   $self->SUPER::Populate($args);
 >  
 >   # initial all the component
 >   $frameA = $self->Frame(relief=>'groove',borderwidth=>'1');    
 >   $frameA1 = $frameA->Text(-relief => 'groove');
 >   $frameA2 = $frameA->Text(-relief => 'groove');
 >  
 >   #packing all the component sequentially
 >   $frameA->pack(-side => 'left', -fill => 'both', -expand => 1);
 >   $frameA1->pack(-side => 'left', -fill => 'both', -expand => 1);
 >   $frameA2->pack(-side => 'left', -fill => 'both', -expand => 1);

Changing to grid, try to replace last two lines with

         $frameA->gridRowconfigure(0, -weight => 1);
         $frameA->gridColumnconfigure(0, -weight => 1);
         $frameA->gridColumnconfigure(1, -weight => 1);
         $frameA1->grid(-row => 0, -column => 0, -sticky => 'nsew');
         $frameA2->grid(-row => 0, -column => 1, -sticky => 'nsew');

It works for me.

Continuing using pack, try to add this bind

         $frameA->bind('<Configure>', [sub {
                 shift;

#               $frameA1->configure(-height => $h, -width => int ($w/2));
#               $frameA2->configure(-height => $h, -width => int ($w/2));
#               $frameA->update;
                 $frameA1->GeometryRequest(int ($w/2), $h);
                 $frameA2->GeometryRequest(int ($w/2), $h);
                 }, Tk::Ev('w'), Tk::Ev('h')]);

I don't know, why setting -height and -width via configure doesn't work.

Regards,

P.



Thu, 24 Mar 2005 01:39:18 GMT  
 resizing control

Hi Pavel,

I always thought that pack and grid should not be used together and I
guess I am wrong. Your sample really help to clarify some
misconception I have regarding TK. Really appreciate for the advice,
everything works fine now.

Thanks

Tun Tao Tsai



Thu, 24 Mar 2005 09:37:01 GMT  
 resizing control

Quote:

> Hi Pavel,

> I always thought that pack and grid should not be used together and I
> guess I am wrong.

Mixing the two geometry managers does not work in one container widget
(frame or toplevel), but you can use different geometry managers in
different widgets.

Quote:
> Your sample really help to clarify some
> misconception I have regarding TK. Really appreciate for the advice,
> everything works fine now.

> Thanks

> Tun Tao Tsai

Regards,
        Slaven

--

Lost in your Tk widget tree? Try
        http://user.cs.tu-berlin.de/~eserte/src/perl/Tk-WidgetDump/



Thu, 24 Mar 2005 17:56:02 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. resizing label resizes parent

2. control C, control Z

3. Controlling Serial Control Lines?

4. Control Menu control...??

5. How to force a window to resize when its widgets are resized?

6. Resizing images using GD.pm

7. Resizing JPG files and more

8. Server Side Image Resizing

9. resizing the objects

10. Using Perl to resize image?

11. frames/resize problem in netscape

12. tk window resizing

 

 
Powered by phpBB® Forum Software