in reply to refreshing a GUI

Re-reading this post, I'm just going to say sorry. I'm not sure I even understand what I meant. Thanks for everything so far, and if you don't mind, I'll post the offending code and you guys can look over it.
sub go { foreach (1..5) { &neighbors_non_edge($radiovar); &neighbors_corners($radiovar); &neighbors_edge($radiovar); &update_go_array(); &print_array(); } }

This sub calls the five subs, in order, to complete a single iteration of the whole program. It's nested in a for loop because I want it to happen five times (printing out each time separately, clearing/refreshing the previous printout on the screen as it goes). This sub is outside the tk gui (so outside MainLoop) as are the five subs it calls.
The code for the button in the gui that calls sub go is
$start_button =$top->Button(-text => "Start the Process", -foreground +=>"red", -command => sub{go()});

I've been looking into the tk::after module. Is that something that I should implement here? If so, where?

thanks again,
john



Faster, faster, faster....till the thrill of speed overcomes the fear of death -Daniel Keys Moran

Replies are listed 'Best First'.
Re: Re: refreshing a GUI
by ariels (Curate) on Jul 05, 2001 at 11:50 UTC
    What your loop is doing is telling Tk that you want to change the configuration of your widgets, but never giving it a chance actually to do it!

    You should call $radiovar->idletasks (or perhaps $radiovar->update) somewhere in your foreach loop (say after update_go_array, if you've finished your reconfiguration by then). See the Tk::Widget manpage for details of these methods. This will give Tk a chance to display the updates you've made.

    On a side note, why are you saying &subroutine() instead of subroutine()?

Re: Your Code
by Zapawork (Scribe) on Jun 28, 2001 at 02:40 UTC
    Your cycling through five iterations before returning to the mainloop. Does this make sense to you? You are changing the contents of the widget 5 times and then returning to the mainloop for it to process the results.

    Unless in some part of those subroutines there is a call back to the mainloop, i'm not sure how you would even do this, then the mainloop, which processes all tk events, would not ever see the changes that are happening.

    If I am entirely missing the point here I apologize. This is just what i see.

    Dave

Re: Re: refreshing a GUI
by Anonymous Monk on Jun 28, 2001 at 13:52 UTC
    The Idea is not about where you store the Code. That could be in a module or an evaled sub or whereever. The Idea is how you *call* your code. You call your code by -command. That means the MainLoop calls it on your behalf through that ref. So your code runs *inside* the MainLoop. It does *not* enter the MainLoop again before it returns. That's the error.