source: project/wiki/eggref/4/pstk @ 37320

Last change on this file since 37320 was 37320, checked in by svnwiki, 3 years ago

Anonymous wiki edit for IP [145.130.119.110]: Clean up dead/obsolete links, add 1.3.0 version info

  • Property svnwiki:title set to PS/Tk
File size: 4.7 KB
Line 
1== PS/Tk
2
3PS/Tk provides an interface to the Tk toolkit, and is an effective tool for creating graphical interfaces. 
4
5[[toc:]]
6
7=== Examples
8
9Several examples can be found in the [[https://github.com/utz82/pstk|git repository]] for this egg, as well as a detailed guide to using Tk from Scheme.
10
11==== Hello World
12
13<enscript highlight=scheme>
14(use pstk)
15
16(tk-start)
17
18(tk/pack
19  (tk 'create-widget 'button 'text: "Hello"
20      'command: (lambda () (display "Hello world") (newline)))
21  'padx: 20 'pady: 20)
22(tk-event-loop)
23</enscript>
24
25==== Simple Dialog
26
27<enscript highlight=scheme>
28(use pstk)
29
30(define (celsius->fahrenheit item)
31  (let ((number (string->number item)))
32    (if (number? number)
33      (+ (* number 9/5) 32)
34      0.0)))
35
36(tk-start)
37(tk/wm 'title tk "Celsius to Fahrenheit")
38
39(let* ((celsius (tk 'create-widget 'entry))
40       (label (tk 'create-widget 'label))
41       (button (tk 'create-widget 'button
42                   'text: 'Calculate
43                   'command: (lambda ()
44                               (label 'configure
45                                      'text: (number->string (celsius->fahrenheit (celsius 'get))))))))
46  ; layout widgets in a grid
47  (tk/grid celsius 'column: 2 'row: 1 'sticky: 'we 'padx: 5 'pady: 5)
48  (tk/grid label 'column: 2 'row: 2 'sticky: 'we 'padx: 5 'pady: 5)
49  (tk/grid button 'column: 2 'row: 3 'sticky: 'we 'padx: 5 'pady: 5)
50  (tk/grid (tk 'create-widget 'label 'text: "celsius")
51           'column: 3 'row: 1 'sticky: 'w 'padx: 5 'pady: 5)
52  (tk/grid (tk 'create-widget 'label 'text: "is")
53           'column: 1 'row: 2 'sticky: 'e 'padx: 5 'pady: 5)
54  (tk/grid (tk 'create-widget 'label 'text: "fahrenheit")
55           'column: 3 'row: 2 'sticky: 'w 'padx: 5 'pady: 5)
56
57  (tk-event-loop))
58</enscript>
59
60=== Tips on Using PS/Tk
61
62* By default, the program {{tclsh8.6}} is called, but an alternative program may be provided as an optional argument to {{(tk-start)}}.  For a distributable application, you can bundle [[http://code.google.com/p/tclkit/|tclkit]] with your application, and call the tclkit application in {{tk-start}}.
63
64* 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. 
65
66 (tk-start "wish85")
67 (tk/message-box 'title: "starting program" 'message: "Press ENTER" 'type: 'ok)
68 (tk-wm title tk "PROGRAM")
69 etc
70
71* It is helpful to put an exception handler around your tk code to prevent orphaned shells, especially when developing your program. e.g.
72<enscript>
73(handle-exceptions
74  exn
75  (tk-end)  ; make sure tk is closed in event of any error
76  ; begin program
77  (tk-start)
78 ; rest of  gui setup
79 )
80</enscript>
81
82* PS/Tk currently does not work on Windows 7 due some problem with Posix/process.  It will simply hang after (tk-start "tclsh85") See http://bugs.call-cc.org/ticket/765 for a workaround (You need to add
83<enscript>
84(set! process (lambda (#!rest rest)
85    (receive (a b c d) (apply process* rest)
86    (values a b c))))
87</enscript>
88
89to your .scm file like this:
90
91<enscript>
92(require-extension pstk)
93
94;; http://bugs.call-cc.org/ticket/765
95;; broken posix/process function under Windows 7 (MingW)
96(set! process (lambda (#!rest rest)
97    (receive (a b c d) (apply process* rest)
98    (values a b c))))
99(tk-start "tclsh85")
100(tk/pack
101  (tk 'create-widget 'button 'text: "Hello"
102      'command: (lambda () (display "Hello world") (newline)))
103  'padx: 20 'pady: 20)
104(tk-event-loop)
105</enscript>
106
107* If you want to display unicode characters then you need to add the following to pstk.scm:
108
109<enscript>
110     (tk-init-string
111       (string-intersperse
112                          '("package require Tk"
113                            "fconfigure stdin -encoding utf-8"
114                            "fconfigure stdout -encoding utf-8"
115                            "if {[package version tile] != \"\"} {"
116                            "    package require tile"
117                            "}"
118</enscript>
119
120Alternatively, add the following in your script:
121<enscript>
122(tk-start)
123(tk-eval "fconfigure stdin -encoding ascii")
124(tk-eval "fconfigure stdout -encoding ascii")
125</enscript>
126
127=== Authors
128
129Kenneth A Dickey, Nils M Holm and Wolf-Dieter Busch created the initial versions of pstk.  This
130port to Chicken, plus some additions, is by [[/users/peter-lane|Peter Lane]].
131
132=== License
133
134BSD 2-clause
135
136=== Requirements
137
138Requires an installation of [[http://www.tcl.tk/software/tcltk/|tcltk]] or [[http://code.google.com/p/tclkit/|tclkit]].
139
140=== Version History
141
142* version 1.3.0: set default tcl/tk runtime to tclsh8.6, Chicken 5 compatibility
143* version 1.2.2: get rid of implicit dependency on {{letrec*}}-semantics in {{letrec}} call (Peter Bex)
144* version 1.2.1: avoid hitting {{apply}} argument limit (Jim Ursetto)
145* version 1.2: removed posix dependency from meta file (felix)
146* version 1.1: working on windows as well as linux
147* version 1.0: first package.
Note: See TracBrowser for help on using the repository browser.