There are at least two ways you can do that. The first would be using presentations
and presentation-to-command-translator
and second would use gadgets (aka. widgets) like push-button
. I guess you haven't learned about presentations
yet, so I would show you how to do it with gadgets.
The below example would have a pane and a push button. when you click the button, you would see "Hello World!" output to the pane.
;;;; First Load McCLIM, then save this in a file and load it.
(in-package #:clim-user)
(define-application-frame example ()
()
(:panes
(app :application
:scroll-bars :vertical
:width 400
:height 400)
(button :push-button
:label "Greetings"
:activate-callback
(lambda (pane &rest args)
(declare (ignore pane args))
;; In McCLIM, `t` or *standard-output is bound to the first pane of
;; type :application, in this case `app` pane.
(format t "Hello World!~%" ))))
(:layouts
(default (vertically () app button))))
(defun run ()
(run-frame-top-level (make-application-frame 'example)))
(clim-user::run)
P.S. One way to learn how to do something in McCLIM is to run and look at clim-demos
. Once you find something interesting and want to know how it is done, look at its source in Examples
directory of McCLIM source.
For Help, it is much better to use IRC chat (#clim on libera.chat) where multiple McCLIM devs hang out.
EDIT: Second example with presentation-to-command-translator
, clicking anywhere in the pane would output "Hello World!" in the pane.
(in-package #:clim-user)
(define-application-frame example ()
()
(:pane :application
:width 400
:display-time nil))
;; Note the `:display-time nil` option above, without it default McCLIM command-loop
;; will clear the pane after each time the command is run. It wasn't needed in previous
;; example because there were no commands involved.
(define-example-command (com-say :name t)
()
(format t "Hello World!~%"))
(define-presentation-to-command-translator say-hello
(blank-area com-say example :gesture :select)
(obj)
nil)
(defun run ()
(run-frame-top-level (make-application-frame 'example)))
(clim-user::run)