From: Kevin Smith Date: 2000-12-18T15:43:44+09:00 Subject: [ruby-talk:7551] Re: Popping up secondary Tk windows Kevin Smith wrote: >harryo@zipworld.com.au (Harry Ohlsen) wrote: >>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 can't copy/paste at the moment (don't ask), but >here's a paraphrased version of my working ruby >code. Hopefully I won't put in a stupid typo that >messes you up. It assumes that the main app has >already created its own root window. > >root = TkRoot.new # root is a singleton--get it >window = TkToplevel.new(root) >window.title('Compose Message') >label = TkLabel.new(window) >label.text('Tl:') >label.grid('row' => '1', 'column' => '0', >'sticky' => 'nw') # could use pack instead >to = TkEntry.new(window) >to.grid('row' => '1', 'column' => '1', 'sticky' >=> 'nsew') # could use pack instead > >This is invoked in response to a command, and >will create a new toplevel window. After this >code returns, the new window will remain open and >the main message loop will serve both windows. > Since perl's DialogBox actually uses TopLevel, and not Dialog, as its base, I am guessing that the code snippet above (forgive formatting) would actually be very close to what you want. The missing element is that my code is modeless, and you want it to be modal. Intepreting from my Perl/Tk book, you would want to do some form of 'grab', and then do a 'waitVariable' to sit around and wait until the user presses a button. Presumably you would have a binding such that pressing a button would fill in the variable you are waiting on. This seems to be the approach used in DialogBox.pm. Good luck, and let me (us) know if you make progress! Kevin