How do you reposition the main window under Perl Tkx?


How do you reposition the main window under Perl Tkx?



Having more or less converted a lot of old Tk scripts over to Tkx I'm stuck for an port for the following function which repositions the window passed in as a parameter in the centre of the screen. I used to call this just before calling MainLoop, by which point Tk had obviously decided on the reqwidth and reqheight values.

sub CenterWindow {     # Args: (0) window to center     # (1) [optional] desired width     # (2) [optional] desired height      my($window, $width, $height) = @_;      $window->idletasks;     $width = $window->reqwidth unless $width;     $height = $window->reqheight unless $height;      my $x = int(($window->screenwidth / 2) - ($width / 2));     my $y = int(($window->screenheight / 2) - ($height / 2));      $window->geometry($width . "x" . $height . "+" . $x . "+" . $y); } 

idletasks can be changed to Tkx::update() if necessary, but I am at a loss to find any obvious translation for the window specific parts of this old Tk routine. Tkx doesn't seem to have an equivalent for reqwidth, reqheight, screenwidth or screenheight retrieveable by cget().

Does the fact that I'm now using a grid layout in Tkx, rather than a pack layout in Tk have any relevance?

BTW I'm running ActivePerl 5.10 on Windows Vista if that makes any difference.




What's the smallest non-zero, positive floating-point number in Perl?

1:



Why can't I get Twitter write access working with Net::Twitter::OAuth?
The geometry manager doesn't matter; that only controls how widgets are laid out within a frame.


Unpack a binary file to a text file - A problem that flips the values
The data you're after is available via the winfo command:.
Perl Print buffering flush
sub CenterWindow {     # Args: (0) window to center     # (1) [optional] desired width     # (2) [optional] desired height      my ($window, $width, $height) = @_;      Tkx::update('idletasks');     $width  ||= Tkx::winfo('reqwidth',  $window);     $height ||= Tkx::winfo('reqheight', $window);      my $x = int((Tkx::winfo('screenwidth',  $window) / 2) - ($width / 2));     my $y = int((Tkx::winfo('screenheight', $window) / 2) - ($height / 2));      $window->g_wm_geometry($width . 


Why doesn't my Perl CGI script work?
"x" .


How can I force unload a Perl module?
$height .


How do I make a time counter as child process that works in parallel to program?
"+" .


How can I cleanly handle error checking in Perl?
$x .

"+" .

$y); }
As far as I can tell, you have to invoke winfo directly, you can't use the OO syntax.. You've probably figured this out already, but when developing with Tkx you need to refer to the Tcl Tk documentation.

The Tkx documentation just describes how the (very thin) translation layer works.

Also, the usenet group comp.lang.perl.tk (or the ptk mailing list bridge to it) is probably the best resource for Tkx questions as at least one of the ActiveState guys behind Tkx can be found there..



82 out of 100 based on 52 user ratings 502 reviews