Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Tk button appearance while its callback runs

by BlueBlazerRegular (Friar)
on Oct 11, 2002 at 14:54 UTC ( [id://204540]=note: print w/replies, xml ) Need Help??


in reply to Tk button appearance while its callback runs

You need to 'update' the screen before the callback runs, like this:

# # Sets the cursor to the 'busy' cursor # $mw->Busy(-recurse => 1); $mw->update(); # # Callback code goes here # $mw->Unbusy; $mw->update();

You aren't limited to just setting the 'busy' cursor - you can change widget colors, disable the button, etc. But you need to refresh the screen or else you won't see your changes.

Pat

Replies are listed 'Best First'.
Re: Tk button appearance while its callback runs
by ff (Hermit) on Oct 11, 2002 at 15:39 UTC
    Hi Pat,
    Hmm, this is not panning out. Within the callback, running the Busy method against the widget that invoked the callback achieves the cursor change as noted above, but I'm still not able to change colors, text, etc. even with the 'update' calls.

    However, you have alerted me to the fact that I was not controlling the cursor appearance either. Silly me, I thought that 'watch' was just cross-referenced incorrectly to an hourglass and didn't test using a different cursor style. Now I see that
    -cursor => 'watch'
    was doing nothing for me.

    Thanks,
    Brig

      Well, yet another of my misconceptions (regarding the needfulness of $mw->update) has been brought out into the light of day (where, hopefully, it will wither away and die).

      After some experimentation, I think I have something that does what you want. I had to combine several different things together, but that appears to the 'Tk' way. So without further ado...

      #!/opt/local/bin/perl -w use strict; use warnings; use Tk; my $button_label = 'Push me'; my $mw = MainWindow->new; $mw->geometry("300x200+20+20"); $mw->title( "Tk Testing" ); my $button; $button = $mw->Button( -textvariable => \$button_label, -underline => 0, -foreground => 'blue', -command => sub { my $saved_label = $button_label; $button_label = 'Ouch!'; $button->configure( -relief => 'flat', -activeforeground => 'red', -activebackground => 'green', ); $button->Busy(-recurse => 1 ); sleep( 10 ); $button_label = $saved_label; $button->configure( -relief => 'raised', -foreground => 'blue', ); $button->Unbusy; }, )->pack(-side => 'top', -anchor => 'center', -fill => 'none', -expand => 0, -padx => 5, -pady => 5, ); MainLoop; exit 0; __END__

      Hope this is useful. Even if it isn't, I've learned something, so it wasn't a complete waste. :)

      Pat

        Dear Monks,

        Thanks for your assistance. My button works as desired now: while my button's callback does its thing, it:

        has a different color
        has different text
        has relief of 'sunken'
        cursor changes to hourglass.

        Surely my user will believe the program is doing SOMETHING while these things are in effect.

        Brig

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://204540]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-03-28 11:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found