Skip Menu |

This queue is for tickets about the Tk CPAN distribution.

Report information
The Basics
Id: 129803
Status: open
Priority: 0/
Queue: Tk

People
Owner: Nobody in particular
Requestors: HEXCODER [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 804.034
Fixed in: (no value)



Subject: Tk:NoteBook incorrect intial layout
This demo shows a wrong initial layout. The button is not contained in its frame. After raising tab 'A' the layout is correct; This is under StrawberyPerl 5.26.2 on Windows 7. Tk_Version 804.034 ========================================= use strict; use warnings; use Tk; use TK::NoteBook; my $mw = new MainWindow; my $nb = $mw->NoteBook()->pack('-expand' => 1, '-fill' => 'both'); my $ta = $nb->add('A', -label => 'A')->pack('-expand' => 1); my $tb = $nb->add('B', -label => 'B')->pack('-expand' => 1); my $zf = $ta->Frame()->pack('-side' => 'top', '-anchor' => 'n', '-expand' => 0, '-fill' => 'x'); my $bz1 = $zf->Button('-text' => '+')->pack('-side' => 'left', '-anchor' => 'n', '-expand' => 1, '-fill' => 'x'); $nb->raise('B'); # results in wrong layout $mw->update; $mw->after(3000); $nb->raise('A'); # raise 'A' corrects it MainLoop;
Subject: Tk:NoteBook incorrect initial layout
Here is a smaller demo. use strict; use warnings; use Tk; use TK::NoteBook; my $mw = new MainWindow; my $nb = $mw->NoteBook()->pack(); my $ta = $nb->add('A', -label => 'A')->pack(); my $tb = $nb->add('B', -label => 'B')->pack(); my $bz1 = $ta->Button('-text' => '+')->pack(); $nb->raise('B'); # results in wrong layout $mw->update; $mw->after(3000); $nb->raise('A'); # raise 'A' corrects it MainLoop;
On 2019-06-12 05:23:52, HEXCODER wrote: Show quoted text
> Here is a smaller demo. > > use strict; > use warnings; > > use Tk; > use TK::NoteBook; > > my $mw = new MainWindow; > my $nb = $mw->NoteBook()->pack(); > my $ta = $nb->add('A', -label => 'A')->pack(); > my $tb = $nb->add('B', -label => 'B')->pack(); > > my $bz1 = $ta->Button('-text' => '+')->pack(); > > $nb->raise('B'); # results in wrong layout > $mw->update; > $mw->after(3000); > $nb->raise('A'); # raise 'A' corrects it > > MainLoop;
Single-stepping with a debugger shows the problem in the raise() method of Tk::NoteBook: the Width and Height calls both return 1, which subsequently causes the wrong layout calculations. The problem is that the notebook widget was never mapped, and without mapping a widget Tk does not know its geometry. A workaround would be to explicitly call $mw->update before the ->raise call. Theoretically this ->update call could also be done within the raise method, but I am reluctant to do so because this could have unwanted visual effects (i.e. every ->update causes the Tk application to redraw itself). Unfortunately I don't know of a way to force Tk to calculate the widget geometry without calling ->update. So probably there's no real fix possible, maybe only a note in the documentation.
Subject: Tk:NoteBook incorrect initial layout
Thanks! I will see if I can debug it myself. I think Tk::NoteBook should behave just like other containers (and the book Mastering Perl/Tk has a description on how to implement the mechanics of 'megawidgets', I think). Will report back, if there is progress. Tried the same demo on Linux (after fixing the typo TK::NoteBook -> Tk::Notebook), and got some different effect. The window is permanently repainted. Something seems to trigger a new calculation repeatedly. Greetings Heiko