guile-gtk-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: about button widget


From: Paul Emsley
Subject: Re: about button widget
Date: Sat, 24 Mar 2007 18:38:00 +0000

On Sat, 2007-03-24 at 17:20 +0100, enrico wrote:
> Ciao *,
> i ask myself if guile-gtk provides a function that returns the id of
> button clicked in case of many buttons are available in a window widget.
> 
> My answer was, i don't know dear Enrico, try to ask to ml ;)

Hi Enrico, 

Why do you need it?  The lambda function that you attach to the callback
captures its environment.  That's one cool things about guile/guile-gtk.
No lookups required.

In this example we have access to button, count, vbox, window and
whatever else existed when the lambda function was created.

If buttons need to know about other button, create the buttons first,
put them in a list (say) and then generate the lambda function
callbacks.  The lambda function will then know about the list of
buttons.

Cheers, 

Paul

-----


(use-modules (gtk gdk)
             (gtk gtk))

(let ((window (gtk-window-new 'toplevel))
      (vbox (gtk-vbox-new #f 0)))

  
  (gtk-container-add window vbox)

  (map (lambda (count) 
         
         (let ((button (gtk-button-new-with-label
                        (string-append "   "
                          (number->string count) "   "))))

           (gtk-box-pack-start vbox button #f #f 2)
           (gtk-signal-connect button "clicked"
                               (lambda ()
                                 
                                 (format #t "captured ~s (uninteresting) and 
~s~%"
                                         button count)))))
       (list 0 1 2 3 4 5 6))

  (gtk-widget-show-all window))

(gtk-main)







reply via email to

[Prev in Thread] Current Thread [Next in Thread]