1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| # helloWorld.tcl
#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"
# load the Gnocl package
package require Gnocl
# create a button, print 'Hello World' to console when clicked.
set but1 [gnocl::button -text "Click Me!" -onClicked {puts "Hello World"}]
# create a container to hold the widget, not necessary but we want to keep the button small
set box [gnocl::box]
# add the button to the container, using -fill {0 0} will restrict the size,
# but allow its position to be adjusted when the window is resized
$box add $but1 -fill {0 0} -expand 1
# create the window, the parameters speak for themselves
gnocl::window -title "helloWorld.tcl" -onDelete {exit} -child $box -widthRequest 200 -heightRequest 50
# not necessary, but programmatically correct
gnocl::mainLoop |