From: nedbrek on
Hello all,

"Jan Kandziora" <jjj(a)gmx.de> wrote in message news:hk2ufl$bna$1(a)online.de...
> shags72 schrieb:
>> I would like it to be an icon to click on
>>
> That's done by the desktop environment.

Yup. For example, in Windows, associate .tcl file with your wish.exe (maybe
wish85.exe, or something like that; maybe in c:\Tcl\bin). I think Ubuntu
has similar association rules. Not sure for other Linux. Maybe just
putting #!/usr/bin/wish on the first line... see the Wiki for the magic
header, something about using find for the path.

>> and have it bring up a gui and have some input and a return. I do not
>> know
>> how and I do know some basic tcl but no tk.
>
> package require Tk
>
> entry .e
> label .l
>
> bind .e <Return> {.l configure -text [expr [.e get]]}
>
> pack .e
> pack .l
> ------------------------------

That is the beauty of Tcl/Tk!

Even more compact:
-----
pack [entry .e]
pack [label .l]

bind .e <Return> {.l configure -text [expr [.e get]])
-----

Check the Tk manual for pack (the packer manages the placement of widgets),
entry (a single line input widget), label (a widget to display a string),
and bind (connect an event to a Tcl script).

You'll be off in no time!

Enjoy!
Ned


From: Richard Owlett on
shags72 wrote:
> HI again. I like I have said before am pretty new at writing tcl code
> which is the only code I know at this time and I want to write a
> simple ap or interface or something like it that does a simple math
> equation. I would like it to be an icon to click on and have it bring
> up a gui and have some input and a return. I do not know how and I do
> know some basic tcl but no tk. Any help would be great and Thanks in
> advance.

You might be interested in "A little multiplication toy" at
http://wiki.tcl.tk/9219 . IIRC it demonstrates much of what you
want. {For some reason I don't seem to be able to access the wiki
today.)

From: shags72 on
On Jan 31, 9:45 am, Richard Owlett <rowl...(a)pcnetinc.com> wrote:
> shags72 wrote:
> > HI again. I like I have said before am pretty new at writing tcl code
> > which is the only code I know at this time and I want to write a
> > simple ap or interface or something like it that does a simple math
> > equation. I would like it to be an icon to click on and have it bring
> > up a gui and have some input and a return. I do not know how and I do
> > know some basic tcl but no tk. Any help would be great and Thanks in
> > advance.
>
> You might be interested in "A little multiplication toy" athttp://wiki.tcl.tk/9219. IIRC it demonstrates much of what you
> want. {For some reason I don't seem to be able to access the wiki
> today.)

You are right that is about what I wanted! I tried to get it to work
with my calculations but haven't had any luck yet. Here is my code and
the original #ed out. The tk window comes up ok but it never comes out
with the answer. I had all of the expr's together but wasn't sure if I
had all of the [] in the right spots so I just went simple. Thanks in
advance.

# proc main {} {
# global a b c
# entry .a -width 5 -textvariable a
# label .* -text *
# entry .b -width 5 -textvariable b
# label .= -text =
# label .c -width 10 -textvariable c
# eval pack [winfo children .] -side left

# foreach factor {a b} {
# trace variable $factor w {recompute}
# }
# }

proc main {} {
global a b c d
entry .a -width 5 -textvariable a
label .+ -text +
entry .b -width 5 -textvariable b
label .- -text -
entry .c -width 5 -textvariable c
label .= -text =
label .d -width 10 -textvariable d
eval pack [winfo children .] -side left

foreach factor {a b c} {
trace variable $factor w {recompute}
}
}

proc recompute {- - - -} {
global a b c d
#catch {set c [expr {$a * $b}]}
if {$c > 4} {
set c 4
}
set a [expr $a / 50]
set b [expr $b / 12]
set c [expr $c / 5]
catch {set d [expr $a + $b]}
catch {set d [expr $d - $c]}
set d [format %1.0f $d]
}

main
From: nedbrek on
Hello,

"shags72" <jerib(a)mtco.com> wrote in message
news:9f6ce4ce-bb0b-4b23-8159-602fe99e8f39(a)b36g2000yqn.googlegroups.com...
> On Jan 31, 9:45 am, Richard Owlett <rowl...(a)pcnetinc.com> wrote:
>> You might be interested in "A little multiplication toy"
>> athttp://wiki.tcl.tk/9219. IIRC it demonstrates much of what you
>> want. {For some reason I don't seem to be able to access the wiki
>> today.)
>
> You are right that is about what I wanted! I tried to get it to work
> with my calculations but haven't had any luck yet. Here is my code and
> the original #ed out. The tk window comes up ok but it never comes out
> with the answer. I had all of the expr's together but wasn't sure if I
> had all of the [] in the right spots so I just went simple. Thanks in
> advance.
>
> proc recompute {- - - -} {

The script called by trace only needs three arguments, should be:
proc recompute {- - -}

> global a b c d
> #catch {set c [expr {$a * $b}]}
> if {$c > 4} {
> set c 4
> }
> set a [expr $a / 50]
> set b [expr $b / 12]
> set c [expr $c / 5]
> catch {set d [expr $a + $b]}
> catch {set d [expr $d - $c]}
> set d [format %1.0f $d]
> }

All these reductions will keep triggering traces, and make all the variables
0! Especially c <= 4, c / 5 (that's integer division {0..4}/5 is always 0).

You should check for which variable {a b c} is being updated, and only
reduce that one, then recompute d (maybe use a different script for each
one).

HTH,
Ned


From: Richard Owlett on
shags72 wrote:
> On Jan 31, 9:45 am, Richard Owlett <rowl...(a)pcnetinc.com> wrote:
>> shags72 wrote:
>>> HI again. I like I have said before am pretty new at writing tcl code
>>> which is the only code I know at this time and I want to write a
>>> simple ap or interface or something like it that does a simple math
>>> equation. I would like it to be an icon to click on and have it bring
>>> up a gui and have some input and a return. I do not know how and I do
>>> know some basic tcl but no tk. Any help would be great and Thanks in
>>> advance.
>> You might be interested in "A little multiplication toy" athttp://wiki.tcl.tk/9219. IIRC it demonstrates much of what you
>> want. {For some reason I don't seem to be able to access the wiki
>> today.)
>
> You are right that is about what I wanted! I tried to get it to work
> with my calculations but haven't had any luck yet. Here is my code and
> the original #ed out. The tk window comes up ok but it never comes out
> with the answer. I had all of the expr's together but wasn't sure if I
> had all of the [] in the right spots so I just went simple. Thanks in
> advance.
>
> # proc main {} {
> # global a b c
> # entry .a -width 5 -textvariable a
> # label .* -text *
> # entry .b -width 5 -textvariable b
> # label .= -text =
> # label .c -width 10 -textvariable c
> # eval pack [winfo children .] -side left
>
> # foreach factor {a b} {
> # trace variable $factor w {recompute}
> # }
> # }
>
> proc main {} {
> global a b c d
> entry .a -width 5 -textvariable a
> label .+ -text +
> entry .b -width 5 -textvariable b
> label .- -text -
> entry .c -width 5 -textvariable c
> label .= -text =
> label .d -width 10 -textvariable d
> eval pack [winfo children .] -side left
>
> foreach factor {a b c} {
> trace variable $factor w {recompute}
> }
> }
>
> proc recompute {- - - -} {
> global a b c d
> #catch {set c [expr {$a * $b}]}
> if {$c > 4} {
> set c 4
> }
> set a [expr $a / 50]
> set b [expr $b / 12]
> set c [expr $c / 5]
> catch {set d [expr $a + $b]}
> catch {set d [expr $d - $c]}
> set d [format %1.0f $d]
> }
>
> main

As a newbie myself, I can't add anything to Ned's description of
what is happening.

I would suggest looking at
http://wiki.tcl.tk/_/gsearch?S=tutorial for a list of tutorials.

Spend time roaming the wiki. The search boxes on the left side of
every page are very useful when something triggers a question.

When I'm modifying a working piece of code, I find it a good idea
to change only one thing at a time. I comment out the original
line of code and put my new code directly below it.

In this case I might have I might have added comments lines that
said what the original program accomplished and what you wished
to accomplish.
First  |  Prev  |  Next  |  Last
Pages: 1 2 3
Prev: Changing icon on script
Next: some GPIB-tcl questions