LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   tcl problem (https://www.linuxquestions.org/questions/programming-9/tcl-problem-711389/)

khodeir 03-13-2009 12:15 PM

tcl problem
 
Hi all
i am making a program that takes a number and convert it to integer and then use it

i do that
Quote:

#!/usr/bin/wish

set labelPath1 ".label1"
set labelPath2 ".label2"

set entryPath1 ".entry1"
set entryPath2 ".entry2"
#############################################################################################
set buttonPath ".button"
label $labelPath1 -text "write you number :"
label $labelPath2 -text "The conersion to integer:"
button $buttonPath -text "Calc"
#############################################################################################
entry $entryPath2 -textvariable entryText2
entry $entryPath1 -textvariable entryText1

#############################################################################################
grid $labelPath1 -row 1 -column 1 -columnspan 5
grid $entryPath1 -row 1 -column 5 -columnspan 5

grid $buttonPath -row 2 -column 2 -columnspan 2

grid $labelPath2 -row 3 -column 1 -columnspan 5
grid $entryPath2 -row 3 -column 5 -columnspan 5
the Gui is not as expected
any help??

taylor_venable 03-13-2009 01:54 PM

Can you describe your problem in more detail please? I can't tell from looking at it what's wrong with it.

khodeir 03-13-2009 02:55 PM

ok man
i thought the output will be

Quote:

write you number "the place of entry"
button here

The conersion to integer:"the other entry"

but the output was

Quote:

"the place of entry"
button here
"the other entry"

taylor_venable 03-13-2009 03:24 PM

Hm, in both Tcl/Tk 8.5 and Tcl/Tk 8.6b1 I see what you expected to see. What version are you using?

khodeir 03-13-2009 03:55 PM

i don't know but i work on rhel 4
and i have slackware but i don't try it yet

jlinkels 03-13-2009 07:43 PM

You are using columnspan 5 for the labels. So they will be stretched over 5 columns. By definition they will be overwritten by the input field which is in column 5.

Code:

grid $labelPath1 -row 1 -column 1 -columnspan 1
grid $entryPath1 -row 1 -column 2 -columnspan 1

grid $buttonPath -row 2 -column 1 -columnspan 1

grid $labelPath2 -row 3 -column 1 -columnspan 1
grid $entryPath2 -row 3 -column 2 -columnspan 1

Play with alignment of the button if you want a more refined layout.

BTW, your error descriptions "it doesn't work" and "result is not as expected" are not very helpful.

jlinkels

khodeir 03-14-2009 01:02 AM

thanks man
but doesn't columnspan tell me the number of column in a row???

jlinkels 03-14-2009 07:42 AM

Usually columnspan tells how many columns are occupied by an element.

I assume in Tk as many columns are created as needed which is determined from the context.

jlinkels

khodeir 03-15-2009 05:13 PM

Thanks man
I have a little question
can tcl deal with negative numbers?
because i have a problem adding or multiplying with negative numbers

jlinkels 03-15-2009 06:33 PM

Yes of course

Code:

% set n -3
-3
% set k [expr 1 + $n]
-2
% set m [expr $k * $n]
6
% set m [expr $k * 3]
-6
%

Perhaps you added a space between the minus and the number?

jlinkels

khodeir 03-15-2009 07:04 PM

ok man
i will check it again

khodeir 03-15-2009 07:49 PM

it works fine
I have a problem
i am making a calculator
i made entry and buttons for numbers and functions(add sub log sin cos)
the one operand functions worked fine for me
i.e i take the data in entry and make function on it (sin cos tan)
my problem with the 2 operand function like add and sub
i don't know how to make the calculator take the number and clear the entry when entering new data and then make calc when he bush the calc button
I only need ideas and i will try to implement it my self :)

jlinkels 03-15-2009 07:56 PM

Sorry, can't help you with that. That is not simple knowledge I have, I have to start thinking on that as well, and I don't have the time for that.

jlinkels

khodeir 03-15-2009 08:20 PM

Thanks for the previous help
really i appreciate your help

taylor_venable 03-15-2009 09:28 PM

For ongoing problems, I suggest trying #tcl on FreeNode or the Tcler's chat (see http://wiki.tcl.tk/1178) -- they're actually joined together so by getting on one you'll be talking on both. I'm on there (via XMPP) as tcv, and most everybody there is quite nice. Also check out the Tcler's Wiki (see http://wiki.tcl.tk/) and the manual pages online (http://www.tcl.tk/man/tcl8.5/).

An important thing to remember with Tcl is that, generally speaking, most things have a string representation. Commands themselves decide how to interpret their inputs. The [expr] command decides to treat things as numbers, and as such it chooses to implement negative numbers as they appear anywhere else. Note that the best syntax to use for [expr] is to enclose the arithmetic in {} like so: set x [expr {-1 + 3 * 2}]. This is more safe for evaluation, less of a chance for variable expansions to throw off the results.


All times are GMT -5. The time now is 08:24 AM.