18. How do I "clear the screen"?

What screen are you trying to clear?

If you are trying to clear a tty (e.g. xterm) screen then try either of the following within your script:

    system "clear";
or
    print `clear`;
(where the choice between these two depends on the rest of the script: the first is fast - but proceeds via fork and may not occur at exactly the time that you want it to in the script).

David and Rachel Weintraub <davidw@cnj.digex.net> recommend using the old termcap.pl p4 library. You might also consider the perl 5 equivalents: Term.pm (especially the Term::Control module), Curses.pm, Perlmenu.pm, PV.

If you are trying to eliminate a TopLevel or a MainWindow then try:

    $main -> destroy;
If you would rather not destroy then try:
    $main->withdraw;    # remove

    $main->deiconify;   # put back
If $w is a sub-window (sub-widget) then
    $w->pack('forget'); # remove if packed (newer Tk-b9.01++) 
    $w->packForget;     # remove if packed (older versions)
    $w->pack(...);      # put back
There are also ways to call low level C-ish versions:
    $w->UnmapWindow; 
but that is for special purposed only....

If you are trying to erase an $item on a Canvas then try:

    delete($item);

(Thanks to the post by <a904209@pluto.tiuk.ti.com> which extended this answer considerably.)


Previous | Return to table of contents | Next