You are looking at historical revision 22079 of this page. It may differ significantly from its current revision.
PS/Tk
PS/Tk provides an interface to the Tk toolkit, and is an effective tool for creating graphical interfaces. A detailed guide to using Tk from Scheme is in the separate documentation.
Examples
Several examples can be found in the svn repository for this egg.
Hello World
(require-extension 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
(require-extension 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
- By default, the program tclsh8.5 is called, but an alternative program may be provided as an optional argument to (tk-start). For a distributable application, you can bundle tclkit with your application, and call the tclkit application in tk-start.
- Under windows, there is a problem with keyboard input. Currently, the fix is to show a dialog box which is dismissed by pressing 'Enter' (not clicking!) directly after starting tk.
(tk-start "wish85") (tk/message-box 'title: "starting program" 'message: "Press ENTER" 'type: 'ok) (tk-wm title tk "PROGRAM") etc
- It is helpful to put an exception handler around your tk code to prevent orphaned shells, especially when developing your program. e.g.
(handle-exceptions
exn
(tk-end) ; make sure tk is closed in event of any error
; begin program
(tk-start)
; rest of gui setup
)
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
Public Domain.
Requirements
Requires an installation of tcltk or tclkit.
Version History
- version 1.2: removed posix dependency from meta file (felix)
- version 1.1: working on windows as well as linux
- version 1.0: first package.