Hello World

(The world's most famous program)

To start the Chicken interpreter, enter

csi

To load the Tk extensions, enter

(require-extension tk)

To start the Tcl/Tk executable, enter

(start-tk)

Tk is ready for its widget definitions.

rootWindow

We create a button:

(define hello-button (tk 'create-widget 'button))

To see it on the root window, we use the geometry manager tk/pack. Enter this:

(tk/pack hello-button)

Now, it is visible:

buttonNoText

To put a text to the button, configure it:

(hello-button 'configure #:text 'Howdy!)

The text is visible:

buttonTextHowdy

When pressed, the button should write a message to the console. Enter this:

(hello-button 'configure #:command 
    (lambda () (print "Greetings Earthlings")))

Now, all is prepared, and we enter the event loop:

(event-loop)

If you press the button, a little message appears in the console window.

screenTextHowdy

To finish the Tk window, use the closing handle at the window decoration. (With my desktop settings, I must make the window wider so that the closing handle appears.)

See also tk, create-widget, button, tk/pack.


© Author | Home | Sitemap