in reply to Handling resizing in pTk

I should have waited a bit longer before posting. I found the answer.

The event to bind is Configure.

Just bind a callback to a Configure event on your widget, and you can reconfigure as you please.

What surprised me was that I could call the widget's configure method in the ConfigureConfigure callback without creating infinite recursion.

The code below shows the technique.

use strict; use warnings; use Tk; my $mw = MainWindow->new(); my $long_text = <<EOT; Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Pellentesque + dictum tempor augue. Sed id pede. Suspendisse a erat a risus tincidu +nt rhoncus. Integer eget risus. Nulla nunc odio, viverra eget, consec +tetuer non, mollis at, felis. In hac habitasse platea dictumst. Nulla + accumsan volutpat eros. Vivamus convallis, eros ut convallis facilis +is, justo ipsum convallis orci, vehicula laoreet purus eros eget ante +. In tempor. Proin varius placerat nisl. Class aptent taciti sociosqu ad litora torquent per conubia nostra, pe +r inceptos hymenaeos. Aenean pretium augue ac nulla. Praesent ante ri +sus, iaculis et, malesuada a, luctus in, orci. Sed erat odio, auctor +sed, molestie vel, volutpat at, elit. Phasellus fermentum ultricies e +st. Aenean interdum elit sit amet est. Donec luctus lacus a turpis. S +ed et risus. Fusce metus. Pellentesque lorem dolor, volutpat in, cong +ue id, luctus et, magna. Nullam congue sagittis orci. Pellentesque ne +c metus. Nulla nulla. EOT my $l = $mw->Label( -text => $long_text, -wraplength => 250, )->pack( -fill => 'both', -expand => 1, ); $l->bind( '<Configure>', => [ \&ResizeMe, Ev('w') ] ); sub ResizeMe { my $l = shift; my $w = shift; # Amazingly, this does not lead to infinite recursion. $l->configure( -wraplength => $w ); } MainLoop;

Update: I forgot to mention, that I figured this out by looking at the Tk::bind POD. The section called "BINDING CALLBACKS AND SUBSTITUTIONS" includes an entry for the 'w' character which returns a width for an event. The event list includes Configure, as does the h/height entry. So, I figured, maybe Configure events are generated when a widget is resized. I tried a quick binding and it worked.


TGI says moo