GrandFather has asked for the wisdom of the Perl Monks concerning the following question:

I have a Tk application that can spend a few seconds working at times and I'd like to set the mouse cursor to be a busy cursor during the busy periods. Is there a way to do that with Tk?


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re: How do I set a busy cursor in Tk
by swampyankee (Parson) on Mar 30, 2006 at 03:46 UTC

    $widget -> Busy;

    Quoting the perldocs on Tk(more specifically, Tk::Widget - Base class of all widgets): "$widget->Busy?(?-recurse => 1?-option = value>?)? This method configures a -cursor option for $widget and (if -recurse = 1> is specified) all its descendants. The cursor to be set may be passed as -cursor = cursor> or defaults to 'watch'. Additional configure options are applied to $widget only. It also adds a special tag 'Busy' to the bindtags of the widgets so configured so that KeyPress, KeyRelease, ButtonPress and ButtonRelease events are ignored (with press events generating a call to bell). It then acquires a local grab for $widget. The state of the widgets and the grab is restored by a call to $widget->Unbusy."

    emc

    "Being forced to write comments actually improves code, because it is easier to fix a crock than to explain it. "
    —G. Steele
Re: How do I set a busy cursor in Tk
by l.frankline (Hermit) on Mar 30, 2006 at 03:57 UTC

    Hi,

    There is an option in Tk, for more details refer to "Learning Perl/TK, Orielly series" book.

    I want to give you some examples:

    -cursor=>cursorname

    Sets the cursor displayed when the mouse cursor is over the menu.

    The following are the cursor names:

    X_cursorbox_spiraldotboxhand2manrightbu ttonsizingtop_tee
    arrowcenter_ptrdouble_arrowheartmiddlebuttonrtl_logospidertrek
    based_arrow_downcircledraft_largeiconmousesailboatspraycanul_angle
    based_arrow_upclockdraft_smalliron_crosspencilsb_down_arrowstarumbrella
    boatcoffee_mugdraped_boxleft_ptrpirates b_h_double_arrowtargetur_angle
    bogositycrossexchangeleft_sideplussb_le ft_arrowtcrosswatch
    bottom_left_cornercross_reversefleurleft_teeques tion_arrowsb_right_arrowtop_left_arrow
    bottom_right_cornercrosshairgobblerleftbuttonrig ht_ptrsb_up_arrowtop_left_corner
    bottom_sidediamond_crossgumbyII_angleright_sidesb_v_double_arrowtop_right_corner
    bottom_teedothand1Ir_angleright_teeshut tletop_side

    Regards,
    Franklin

    Don't put off till tomorrow, what you can do today.

Re: How do I set a busy cursor in Tk
by jdtoronto (Prior) on Mar 30, 2006 at 08:46 UTC
    Whilst what has been said is quite true, one essential piece of info is missing, as soon as you change the cursor name you must tell the mainloop to update so that the new cursor appears! Obviously you should do this JUST BEFORE your app goes into 'busy' mode.
    $mw->configure( -cursor => 'watch' ); $mw->update;
    Is what I use.

    jdtoronto