[ltk-user] any workaround for missing tkwait?

Antonio Bonifati antonio.bonifati at gmail.com
Sat Jul 21 15:32:17 UTC 2012


Me again,
please forgive me if I ask silly questions.

I am trying to implement a Javascript-like prompt dialog, where there is a  
message, an entry and an ok/cancel button.

Since LTK does not have tkwait, how should I make my function return the  
entry text when the user clicks "ok" or closes the popup window? I know I  
can get an entry value with the "text" accessor, but I do not know when to  
call it. The purpose of tkwait in this case is to wait until a window is  
closed and after that I can return the last value inputted by the user.

Is it probably better to inline the Tcl/Tk code without trying to convert  
it to Lisp? How do I do that? This is the Tk code I am trying to implement  
in LTK:

proc prompt { message } {
   global ReturnedString
   set ReturnedString ""

   toplevel .w
   label .w.l -text $message
   entry .w.e -textvariable ReturnedString

   frame .w.f
   button .w.ok -text "OK" -command { destroy .w }
   button .w.canc -text "Cancel" \
     -command  { set ReturnedString ""; destroy .w }

   pack .w.ok .w.canc -side left -in .w.f
   pack .w.l .w.e .w.f

   tkwait window .w
   return $ReturnedString
}


And this is my first failed attempt:

(defun prompt-for-string (message)
   (let ((e))
     (with-ltk ()
       (let* ((w (make-toplevel nil))
              (l (make-instance 'label :master w :text message))
              (b (make-instance 'button :master w :text "OK"
                   :command (lambda () (destroy w)))))
         (setf e (make-instance 'entry :text "default" :master w))
         (pack (list l e b))))
    (print (text e))))

Even if I close all the tk windows, the entry text is never printed.




More information about the ltk-user mailing list