in reply to pTk popup not returning value and not locking calling window

The short answer is that it doesn't wait. The longer reason involves how your function intereacts with the event loop. Your &show_list function sets up and displays the window, probably by making a new TopLevel (we'll call this new TopLevel $dialog). Then, the function returns -- it has no way of knowing that it needs to wait for input; indeed, there is no way to make it stick around inside the subroutine waiting for input. All of the input has to be handled via the event loop. So the only way to do this is to split things up.

As the poster above said, you need to make $dialog modal. The only time when you're guaranteed to know the value of the variable is when you close $dialog -- so attach all of your computations, etc, to the callback on the "OK" button on $dialog.

Hope this helps -- if not, ask and I'll post an example of what I mean.

  • Comment on Re: pTk popup not returning value and not locking calling window

Replies are listed 'Best First'.
RE: Re: pTk popup not returning value and not locking calling window
by el-moe (Scribe) on Oct 09, 2000 at 23:38 UTC
    Here is the OK button from the popup window.
    my $ok_but = $bf->Button( -text => 'Continue', -width => 10, -command => sub { ($idx) = $list_box->curselection(); if ( defined $idx ){ $job = $jobs[$idx]; $mw->destroy(); } else { $mw->destroy(); } )->pack(-side => 'bottom', -padx => 10, -pady => 5);
    . . . at the end of the subroutine i have
    $top->Mainloop(); return $job if defined $job; return 0;
    I must be missing something very obvious or I've been looking at the code too long to see my mistake. Because it always returns 0 before I even click 'Continue'.

    Thanks for the help.
      I'm not a TK guy, but looking at your code, this would occur if $idx wasn't defined. Have you put some debug code at the point to make sure you know which path your're taking on the if (defined $idx) statement?

      --Chris

      e-mail jcwren
        I removed the debugging print statements before I posted here. Everything is set as I expect it to be within this section of code... but the popup doesn't wait... therefore, my calling window/program doesn't ever get the value I have selected.

        To get this project off of my plate I just grew my original window and placed the list into it. But I still have to understand what I'm doing incorrectly because, even though I don't have to use Tk very often, I still have some programs I've inherited that I must maintain. And they're chock full of pTk stuff.

        Thanks for the help.