Popping up secondary Tk windows 
Author Message
 Popping up secondary Tk windows

I've written a simple Tk-based GUI using Ruby and, so far, I've been
able to work out how to do everything I need by reading Tcl and perl
Tk documentation or from searches on Google.

However, I've now hit a bit of a brick wall.  I have a situation where
I want to pop up a data entry window at the current cursor location,
to allow the user to enter a label to associate with an item on the
screen.

Can someone point me at an example of code that does this in any
language at all?

I know there are pop-up dialogs that contain just buttons, for
confirmation of actions and so on, but can't work out how to create an
arbitrary secondary window of my own design.

I could just make the data entry field part of the window proper, but
that would mean it's there all the time, rarther than just when needed
and it would also disassociate the data entry field from the specific
item that is being addressed.

This seems like such a fundamental thing that it must be done all the
time, but as I say I haven't been able to find an example anywhere.

Note that while I would like to be able to specify the position where
the window pops up (so I can place it near the cursor), just being
able to do it at all would be a start.



Fri, 06 Jun 2003 04:41:26 GMT  
 Popping up secondary Tk windows

Quote:
> I've written a simple Tk-based GUI using Ruby and, so far, I've been
> able to work out how to do everything I need by reading Tcl and perl
> Tk documentation or from searches on Google.

> However, I've now hit a bit of a brick wall.  I have a situation where
> I want to pop up a data entry window at the current cursor location,
> to allow the user to enter a label to associate with an item on the
> screen.

> Can someone point me at an example of code that does this in any
> language at all?

> I know there are pop-up dialogs that contain just buttons, for
> confirmation of actions and so on, but can't work out how to create an
> arbitrary secondary window of my own design.

> I could just make the data entry field part of the window proper, but
> that would mean it's there all the time, rarther than just when needed
> and it would also disassociate the data entry field from the specific
> item that is being addressed.

> This seems like such a fundamental thing that it must be done all the
> time, but as I say I haven't been able to find an example anywhere.

> Note that while I would like to be able to specify the position where
> the window pops up (so I can place it near the cursor), just being
> able to do it at all would be a start.

        use strict;
        use Tk;
        use Tk::DialogBox;
        use vars qw/$MW/;

        my $MW = tkinit;
        $MW->Button(-text => 'Dialog', -command => \&dodialog)->pack;
        MainLoop;

        sub dodialog {
            my $dialog = $MW->DialogBox(-buttons => ['OK', 'Cancel']);
            my $frame = $dialog->add('Frame')->pack;

            # add whatever widgets you want to $frame
            $frame->Label(-text => 'Field 1')->grid(-row => 0, -col => 0);
            $frame->Entry()->grid(-row => 0, -col => 1);
            $frame->Label(-text => 'Field 2')->grid(-row => 1, -col => 0);
            $frame->Entry()->grid(-row => 1, -col => 1);

            $dialog->Show;
            $dialog->destroy;
        }

--
Marc Dashevsky  (remove "_" from address to reply by e-mail)



Fri, 06 Jun 2003 05:38:22 GMT  
 Popping up secondary Tk windows


Quote:
>I've written a simple Tk-based GUI using Ruby and, so far, I've been
>able to work out how to do everything I need by reading Tcl and perl
>Tk documentation or from searches on Google.

>However, I've now hit a bit of a brick wall.  I have a situation where
>I want to pop up a data entry window at the current cursor location,
>to allow the user to enter a label to associate with an item on the
>screen.

Try looking for toplevel windows in the Tcl/Tk documentation.  How
exactly this translates into Ruby though, I have *no* idea!  Alas,
there's not enough time in the day to learn yet-another scripting
language (alas.)

Donal.
--
Donal K. Fellows (at home)
--
FOOLED you!  Absorb EGO SHATTERING impulse rays, polyester poltroon!!
      (WARNING: There is precisely one error in this message.)



Fri, 06 Jun 2003 08:23:07 GMT  
 Popping up secondary Tk windows

Quote:
> I want to pop up a data entry window at the current cursor location,
> to allow the user to enter a label to associate with an item on the
> screen.

This is an example in Tcl of you can create a transient modal dialog
box.
The ShowWindow procedure can create a toplevel that contains all the
widgets you like. If you want the second window to appear at the
current cursor location (on top of the invoking button?) I think it's
best to take care of that in the ShowWindow procedure as well.

#
proc ShowWindow {w parent} {
   global ${w}isDone

   if {![winfo exists $w]} {
      toplevel $w
      button $w.b -text "Close" -command "set ${w}isDone 1"
      pack $w.b
   }
   wm deiconify $w
   wm transient $w $parent
   grab $w
   focus -force $w
   vwait ${w}isDone
   wm withdraw $w
   grab release $w
   return

Quote:
}

toplevel .w
button .w.b -text "Press me!" -command "ShowWindow .w2 .w"
pack .w.b

Sent via Deja.com
http://www.deja.com/



Fri, 06 Jun 2003 20:07:10 GMT  
 Popping up secondary Tk windows
My sincere thanks to Marc, Donald and Joakim!

While trying to pop up that little window, I've read the Tk
documentation approximately 1000 times ... perhaps I'm exaggerating
slightly, but it certainly feels liek that :-).

For some reason I had tunnel vision, looking for something that
mentioned the word "Dialog".

I was able to convert the small sample of Tcl code that Joakim posted
into Ruby reasonably easily and I now have what I want!

What would I do without the web?!

Thanks again people.

I'm sure you'll hear from me again when I hit the next brick wall :-).



Sat, 07 Jun 2003 05:22:45 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Pop Ups

2. Pop Ups

3. Associating Tk Windows with non-Tk windows

4. new window pop up via button

5. Pop Up Window for FormMail

6. ANNOUNCE: Tutorial # 38: A CGI script incorporating a pop-up window

7. perl output to pop-up window

8. pop-up window problem

9. POP UP window

10. POP up window

11. How to stop cmd Windows Pop-up on NT

12. Pop Up Windows on Several Platforms

 

 
Powered by phpBB® Forum Software