Re: beginner's question: what's returned by a widget creation function?

From: Erick Gallesio <eg_at_kaolin.unice.fr>
Date: Mon, 27 Mar 1995 13:45:46 +0100

> Paul Shannon writes

> I am confused about the type of object returned from an STk widget
> creation function. If I create my own variable, and assign to it the
> value returned by the widget creation function, sometimes I can use it,
> and sometimes I cannot.
>
>
> (define widget
> (text '.textWidget :width 80 :height 10
> :borderwidth 1 :relief 'sunken :setgrid #t))
>
> ;; here I can treat my variable as equivalent to the tcl-style name
>
> (pack widget)
>
> ;; but here I have trouble: my variable does not seem to be a real function
>
> (widget 'insert 'end (format #f "------- widget insert-----------~%"))
>
> ;; error message is "eval: bad function in : (widget..."
>
> ;; but this more traditional form *does* work
> (.textWidget 'insert 'end (format #f "------- .textWidget insert-----------~%"))
>
This weirdness is due to the way parameters are passed to the Tk lib. When you
call a Tk wiget constructor such as text, it returns a symbol which is the
name of the created object. So the previous define is as
        (text '.textWidget .......)
        (define widget '.textWidget)

When calling a function which is a Tk command, symbols are passed as is to the
Tk lib function. So when you do "(pack widget)", the scheme evaluator
evaluates
widget (which gives .textWidget) and pass it to Tk unmodified. But
        (widget 'insert ....)
doesn't work since widget denotes a symbol and not a function. You should
do something like
        (define (symbol->widget s)
            (string->widget (symbol->string s)))

        ((symbol->widget s) 'insert ...)

Or more symply (if the goal was to avoid the use of name using dots)
        (text '.textWidget .......)
        (define widget .textWidget) ; No quote here to have a function
        (pack widget) ; Conversion widget->string is automatic
        (widget 'insert ...)

Hope this helps




                -- Erick
Received on Mon Mar 27 1995 - 13:45:47 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST