Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

PS/Tk

PS/Tk provides an interface to the Tk toolkit, and is an effective tool for creating graphical interfaces.

  1. Outdated egg!
  2. PS/Tk
    1. Examples
      1. Hello World
      2. Simple Dialog
    2. Tips on Using PS/Tk
    3. Authors
    4. License
    5. Requirements
    6. Version History

Examples

Several examples can be found in the git repository for this egg, as well as a detailed guide to using Tk from Scheme.

Hello World

(use pstk)

(tk-start)

(tk/pack 
  (tk 'create-widget 'button 'text: "Hello" 
      'command: (lambda () (display "Hello world") (newline)))
  'padx: 20 'pady: 20)
(tk-event-loop)

Simple Dialog

(use pstk)

(define (celsius->fahrenheit item)
  (let ((number (string->number item)))
    (if (number? number)
      (+ (* number 9/5) 32)
      0.0)))

(tk-start)
(tk/wm 'title tk "Celsius to Fahrenheit")

(let* ((celsius (tk 'create-widget 'entry))
       (label (tk 'create-widget 'label))
       (button (tk 'create-widget 'button
		   'text: 'Calculate
		   'command: (lambda () 
			       (label 'configure 
				      'text: (number->string (celsius->fahrenheit (celsius 'get))))))))
  ; layout widgets in a grid
  (tk/grid celsius 'column: 2 'row: 1 'sticky: 'we 'padx: 5 'pady: 5)
  (tk/grid label 'column: 2 'row: 2 'sticky: 'we 'padx: 5 'pady: 5)
  (tk/grid button 'column: 2 'row: 3 'sticky: 'we 'padx: 5 'pady: 5)
  (tk/grid (tk 'create-widget 'label 'text: "celsius") 
	   'column: 3 'row: 1 'sticky: 'w 'padx: 5 'pady: 5)
  (tk/grid (tk 'create-widget 'label 'text: "is") 
	   'column: 1 'row: 2 'sticky: 'e 'padx: 5 'pady: 5)
  (tk/grid (tk 'create-widget 'label 'text: "fahrenheit") 
	   'column: 3 'row: 2 'sticky: 'w 'padx: 5 'pady: 5)

  (tk-event-loop))

Tips on Using PS/Tk

(tk-start "wish85")
(tk/message-box 'title: "starting program" 'message: "Press ENTER" 'type: 'ok)
(tk-wm title tk "PROGRAM") 
etc
(handle-exceptions
  exn
  (tk-end)  ; make sure tk is closed in event of any error
  ; begin program
  (tk-start)
 ; rest of  gui setup
 )
(set! process (lambda (#!rest rest)
    (receive (a b c d) (apply process* rest)
    (values a b c))))

to your .scm file like this:

(require-extension pstk)

;; http://bugs.call-cc.org/ticket/765
;; broken posix/process function under Windows 7 (MingW)
(set! process (lambda (#!rest rest)
    (receive (a b c d) (apply process* rest)
    (values a b c))))
(tk-start "tclsh85")
(tk/pack 
  (tk 'create-widget 'button 'text: "Hello" 
      'command: (lambda () (display "Hello world") (newline)))
  'padx: 20 'pady: 20)
(tk-event-loop)
     (tk-init-string
       (string-intersperse
                          '("package require Tk"
                            "fconfigure stdin -encoding utf-8"
                            "fconfigure stdout -encoding utf-8"
                            "if {[package version tile] != \"\"} {"
                            "    package require tile"
                            "}"

Alternatively, add the following in your script:

(tk-start)
(tk-eval "fconfigure stdin -encoding ascii")
(tk-eval "fconfigure stdout -encoding ascii")

Authors

Kenneth A Dickey, Nils M Holm and Wolf-Dieter Busch created the initial versions of pstk. This port to Chicken, plus some additions, is by Peter Lane.

License

BSD 2-clause

Requirements

Requires an installation of tcltk or tclkit.

Version History