File: tk-mini.tcl

package info (click to toggle)
nsf 2.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 13,208 kB
  • sloc: ansic: 32,687; tcl: 10,723; sh: 660; pascal: 176; javascript: 135; lisp: 41; makefile: 24
file content (37 lines) | stat: -rw-r--r-- 987 bytes parent folder | download | duplicates (4)
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
#
# Tiny Tk example scriped based on NX.
#
# image::tk-mini.png[]
#

package require Tk
package require nx::trait

nx::Class create MyClass {
  #
  # A sample application class that creates a text entry field bound
  # to an instance variable. When the provided button is pressed, the
  # content of the variable is placed into an additional output label.

  #
  # The callback trait imports methods "callback" and "bindvar":
  #
  :require trait nx::trait::callback

  :public method button-pressed {} {
    # When this method is invoked, the content of the ".label" widget
    # is updated with the content of the instance variable "myvar".
    .label configure -text ${:myvar}
  }

  :method init {} {
    wm geometry . -500+500
    pack [label .title -text "Type something and press the start button ..."]
    pack [entry .text -textvariable [:bindvar myvar]]
    pack [label .label]
    pack [button .button -text start -command [:callback button-pressed]]
  }
}
  
MyClass new