1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| #---------------
# gladeXMLTest1.tcl
#---------------
# William J Giddings
# 30-Nov-2009
#---------------
#!/bin/sh
# the next line restarts using tclsh \
exec tclsh "$0" "$@"
package require Gnocl
# load a simple glade file, containing three buttons in a horizontal row
# the variable glade1_widgets contains a list of all widgets created
# by loading this file, they will include the names given in the glade file itself
# along with the names assigned when registering these with Tcl
set glade1 button1.glade
set glade1_widgets [gnocl::glade new $glade1]
# for convenience sake, create a list of aliases for these new widgets
# we can use the glade widget names to do this, to make things manageable
foreach item $glade1_widgets {
foreach {gnocl glade} $item {}
set $glade $gnocl
}
# in the glade file the toplevel window is named window1
# lets resize, rename and centre it on screen
$window1 configure -title "Glade Test" -width 320 -height 200
$window1 centre ;# or 'center' if you wish
# we can now access the widget attributes as these are registered with gnocl!
$button1 configure -icon "%#New" -onClicked { puts "NEW! from %w" }
$button2 configure -icon "%#Open" -onClicked { puts "Open! from %w" }
$button3 configure -icon "%#Save" -onClicked { puts "Save! from %w" }
# as there needs to be a container for these widgets we can get its name with
set box [$window1 cget -child]
# and, of course, add new widgets too!
$box add [gnocl::toggleButton -text "CLICK ME!"]
gnocl::mainLoop |