newlisp-tk Entry widget does not display textvariable

Started by jp, March 20, 2004, 10:10:26 PM

Previous topic - Next topic

jp

I have been trying to mimic the passing of a tcl variable into the newlisp-tk entry widget but alas, regardless the way I am trying to bring the variable into the entry widget it fails.



============ test.tcl



set ok {Entry!}

wm title .  $ok

entry .e -width 30 -textvariable ok

pack .e



=========== test.lsp



(define (test)

 (tk "if {[winfo exists .test] == 1} {destroy .test}")

 (tk "toplevel .test")

 (set! ok (tk "set display {entry!}"))

 (tk "wm title .test " ok)

 (tk "entry .test.e -width 30 -textvariable " ok)

 (tk "pack .test.e")

 )



Here the variable is assigned to the tk widget title but fails to be acknowledged by the entry widget.

Needless to say I have tried all sorts of combinations which come to the mind; nothing seems to let newlisp-tk to give a pre-established variable to the entry widget. Could someone be so kind to cast some light on it!

HPW

#1
Hello jp,

Welcome to the board.



Do not mix up variables in the TCL memory with the variables in newLISP.



(define (test)
(tk "if {[winfo exists .test] == 1} {destroy .test}")
(tk "toplevel .test")
(tk "global display;set display {entry!}")
(tk "global display;wm title .test $display")
(tk "entry .test.e -width 30 -textvariable display")
(tk "pack .test.e")
)
Hans-Peter

Lutz

#2
You also could put everything in one string, limited by [text] ...[/text]



(define (test)

(tk

[text]

if {[winfo exists .test] == 1} {destroy .test};

toplevel .test;

global display;

set display {entry!};

wm title .test $display;

entry .test.e -width 30 -textvariable display;

pack .test.e;

[/text]

))



I think the important thing here to mention is, that the -textvariable wants a variable name, not the contents string. And ist seems to work only with a top level variable. Taking the 'global display' statement away, things don't work anymore. Everyting newLISP passes to TCL/TK will be executed not at top level, but inside a subroutine, this is why the 'global display' statement was necessary.



Lutz

jp

#3
Thanks a lot Hans-Peter and Lutz for the prompt replies



Actually, I was aware that –textvariable expected a variable name and I did make an attempt to declare display as global but as I could not chain it properly it did fail so I made a synoptic representation instead.

Perhaps a paragraph on the newlisp-tk documentation should be devoted on the proper chaining of commands for the interfacing between newlisp and tk.

Now with the overcoming of the hurdles interfacing the tk entry widget nothing stand in the way of a true interactivity between newlisp and tk.



Jean-Pierre

Lutz

#4
Thanks Jean-Pierre for the suggestion and welcome to the discussion forum.



The next version of the manual will expand on this a little bit more. What we really need is a comprehensive example with all the basic widgets in it, explaining and showing all the specifics when interacting between newLISP and Tcl/Tk. I hope one day I will get around doing it.



Lutz

jp

#5
I realise, if one finds the constant calling of the global variable inopportune, one can directly access the variable with the following...



(define (test)

   (tk "if {[winfo exists .test] == 1} {destroy .test}")

   (tk "toplevel .test")

   (tk "variable display")

   (tk "set display {entry!}")

   (tk "wm title .test $::display")

   (tk "entry .test.e -width 30 -textvariable display")

   (tk "pack .test.e")

   )



Jean-Pierre

Lutz

#6
It works for the title but then I still get "cant read ::display no such variable", I think there was some thing still in your Tcl/Tk namespace from before? Try it with a fresh start of newLISP-tk.



Lutz

jp

#7
Indeed you are right; under a new session newlisp fails to find the variable.



Jean-Pierre


Quote from: "Lutz"It works for the title but then I still get "cant read ::display no such variable", I think there was some thing still in your Tcl/Tk namespace from before? Try it with a fresh start of newLISP-tk.



Lutz


But the following seems to work!



(define (test)

(tk "if {[winfo exists .test] == 1} {destroy .test}")

(tk "toplevel .test")

(tk "variable display")

(tk "set ::display {entry!}")

(tk "wm title .test $::display")

(tk "entry .test.e -width 30 -textvariable ::display")

(tk "pack .test.e")

)



Jean-Pierre

Lutz

#8
thanks Jean-Pierre, I will include this example in the manual, because the question about 'how to keep variable state' is asked frequently. It seems that the key is the 'variable varName' declaration and the reference to it with ::varName



Lutz

jp

#9
Actually, 'variable ::varName' declaration and the reference to it with ::varName



The advantage of having direct access to tcl variables is to let tk have as many variables as it is deemed necessary for the good conduct of tk widgets processes, but also that newlisp can always modify them at will!



Jean-Pierre


Quote from: "Lutz"thanks Jean-Pierre, I will include this example in the manual, because the question about 'how to keep variable state' is asked frequently. It seems that the key is the 'variable varName' declaration and the reference to it with ::varName



Lutz

Lutz

#10
It seems that the variable declaration (variable ::display) is not necessary at all. The global namespace prefix :: seems to be enough, and 'set' then instoruces the variable:



(define (test)

(tk "if {[winfo exists .test] == 1} {destroy .test}")

(tk "toplevel .test")

(tk "set ::display {entry!}")

(tk "wm title .test $::display")

(tk "entry .test.e -width 30 -textvariable ::display")

(tk "pack .test.e")

)



Lutz

ps: see "Practical Programming in Tcl and Tk" by Brent B. Welch, p.198

HPW

#11
>ps: see "Practical Programming in Tcl and Tk" by Brent B. Welch, p.198



This is correct for the third edition.



For the current fourth edition take a look at p.208.



;-)
Hans-Peter

newdep

#12
And in the Second Edition its neighter on 198 nor 208 but at 170 :-)

(if we're talking about the global namespace callbacks..)
-- (define? (Cornflakes))

jp

#13
> It seems that the variable declaration (variable ::display) is not necessary at all.



I guess, it will depend entirely under which context we want the tcl variables to operate on, my impression is from the standpoint of newlisp, (variable display) will always be sufficient.



Jean-Pierre

gerhard zintl

#14
(define (test)

(tk "if {[winfo exists .test] == 1} {destroy .test}")

(tk "toplevel .test")

(tk "set ::display {entry!}")

(tk "wm title .test $::display")

(tk "entry .test.e -width 30 -textvariable ::display")

(tk "pack .test.e")

)

I'm just starting to experiment with newLisp.

How could you send back the content of the entry in ::display to newLisp?

Thanks in advance.

Gerhard Zintl