From: Marc Dashevsky Date: 2000-12-18T06:40:02+09:00 Subject: [ruby-talk:7517] Re: Popping up secondary Tk windows In article <3a3d2135.347071482@news-server>, harryo@zipworld.com.au says... > 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)