in reply to Re: Basic questions of Tk programming
in thread Basic questions of Tk programming

Hello haj and bravo,

when I read your reply it made sense. I was surprised to read:

> Calling sleep has the same effect: It hands over control. Tk paints the screen and ... waits. It does not get any events, though. Instead, your Initialize routine wakes up and continues, happy to use the Tk screen. The program use the Tk screen drawing capability, but not the Tk event loop. So should be pack geometry manager to draw the screen.This can be reduced to:

## BAD CODE !! use strict; use warnings; use Tk; my $number = 1; my $mw = MainWindow->new; my $label = $mw->Label(-textvariable =>\$number)->pack(); # sleep 5; MainLoop; while (1){ $number++; $label->update; sleep 1;}

..without the never called MainLoop

By other hand, uncommenting the sleep 5; MainLoop; line pack does not draw the screen, so the screen drawing capability cannot be proved by me.

For sure is buggy code, but can be useful to inspect the internal machineries of Tk

The error: Tk::Label=HASH(0x39a2828) is not a Tk object at textlabel_reduced.pl line 11. only shows closing the the program with the X but no sending CTRL-C in the console.

A final note: perlmonks is the last place on earth (<- thanks to English native ;) last remaining place on earth to get support on perl Tk :)

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^3: Basic questions of Tk programming
by tybalt89 (Monsignor) on Jan 24, 2025 at 10:54 UTC

    It's not the sleep that draws the screen, it's the ->update!

    "A final note: perlmonks is the last place on earth to get support on perl Tk :)"
    This makes my sad. I think I have been quite helpful.

      Sorry tybalt89! marto is right below.. I intended last remaining place to get support on perl Tk.

      Also and without adulation, after zentara retired you are the best Tk guru here around.

      About the update ..yes for sure, but I supposed pack not sleep

      ..sorry for the miswriting!

      L*

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re^3: Basic questions of Tk programming
by marto (Cardinal) on Jan 24, 2025 at 11:01 UTC

    "A final note: perlmonks is the last place on earth to get support on perl Tk :)"

    Perhaps this is lost in translation, while not a Tk user myself I do see Tk threads reasonably often with much help & advice given. For clarity, by the statement above do you mean that once someone posts here they don't go anywhere else for Tk help?