Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

beginners guiding 1

Status
Not open for further replies.

kukelyk

Technical User
Mar 23, 2005
57
HU
hi
im new in tcl, im not a programmer, so i have many many problems...
my problem is finding the value of a numerical variable in a string.. how can i do this?
the string match command seems not to work..
thanks, kukelyk
 
could anybody give a link with TCL tutorials?
 
can i create a window, where i can define variables, which i can use later in the program?
how?
 
My view, not shared by everyone on this forum, is that the best Tcl/Tk tutorial is contained in the help files and the Tk Demos, both of which are part of the ActiveState download. There is also Brent Welch's book, Practical Programming in Tcl and Tk.

As to your stated problem, finding a numerical value in a string, I'm not sure I understand but I'll offer some tips.
Let's say your string is as follows:
"the value of temperature is 42 degrees" and you want to find the number, 42, and assign it to a variable, temp. Let's say the string variable is s1.
So
set s1 "the value of temperature is 42 degrees"
#now find the numeric value in the string
#if you know that the number is separated by white space from the non-number, you can treat s1 as a list:
foreach w $s1 {
if [string is integer $w] {set temp $w};#for integers
if [string is double $w] {set temp $w};#for reals
}

#alternatively, you can use regexp
regexp {[0-9]+} $s1 temp

Bob Rashkin
rrashkin@csc.com
 
sorry..
the problem is the next:
i have two variables:
a floating-point, and a string.
id like to search in the string (which may contain letters, or / signs..) for the value of the floating-point variable
like:
if{string match "*$var*" $varString}..
 
Try
if {[string first $var $varString] != -1} ...

Bob Rashkin
rrashkin@csc.com
 
If you want to use "match" I think your {} were doing some unwanted delaying of the substitution. You would do it:
if [string match "*$var*" $varString] {...}

Bob Rashkin
rrashkin@csc.com
 
i said, that im not a programmer, so i dont know all the possibilities of the programming...
..i know , what i want, but dont know the way..
 
i have an other problem:
i need a script which is similar to the demo called dataent.ui.tcl of SpecTcl1.1
(what consist of a table with two columns, in the 1st column there are labels, in the 2nd there are entries.
I modified it, and left only two rows: two entries with their labels.
but i can execute it only with the specTcl installed..
 
i use tcl to create documentation with a software,
which run the shell, but i don't know more about it...
the problem is there are no main window, what the script could use..IMHO..
the script, what the SpecTcl made starts with:
# root is the parent window for this user interface

i need a window with a 2x2 table..
it seems that i need the Tk_CreateAnonymousWindow command,
but i dont understand its arguments:
interp, parent, topLevScreen

could anybody write the script that creates me a window?
 
thanks Bong, your code works well..here is a small star...
 
Let's distinguish between what it is you want to do and using a "table", since that might not be the best way to do it. First of all, I don't know anything about SpecTcl; maybe someone else can tell you about that.

There is package called TkTable that makes table maniputlation easy. It requires loading of the .dll:
load tktable.dll
Then you need to build the table widget, here with scrollbars:
table $w.t -yscrollcommand "$w.yscr set" -xscrollcommand "$w.xscr set"
scrollbar $w.yscr -command "$w.t yview"
scrollbar $w.xscr -command "$w.t xview" -orient horizontal
pack $w.yscr -side right -fill y
pack $w.t -side top
pack $w.xscr -side top -fill x

Then you configure the table: number of rows, number of columns, widths, colors, headers, etc., and the associated [red]matrix variable[/red], in this case, "m1".
$w.t configure -variable m1 -bg white -width 12 -height 8
$w.t configure -rows $i1 -titlerows 1
$w.t configure -cols 5 -colwidth 16


That's all well and good but maybe more than you need to just have a 2x2 set of labels and entries. I think a better way is as follows:
#First nest 2 frames in a "super-frame" from left to right
pack [frame .f1 -borderwidth 4] -side top
pack [frame .f1.1 -borderwidth 4] -side left
pack [frame .f1.2 -borderwidth 4] -side left

#now in the leftmost frame, .f1.1, put your labels from top to bottom
pack [label .f1.1.lb1 -text "label 1"] -side top
pack [label .f1.1.lb2 -text "label 2"] -side top

#now in the next frame, .f1.2, put your entries from top to bottom
pack [entry .f1.2.en1 -textvariable var1] -side top
pack [entry .f1.2.en2 -textvariable var2] -side top



_________________
Bob Rashkin
rrashkin@csc.com
 
i have no tktable.dll :(
(i have Wish84, VisualTcl, SpecTcl, Ased, but they dont contain it..)

the spectcl made it:

# interface generated by SpecTcl version 1.1 from C:/Program Files/SpecTcl1.1/demo/adatbe.ui
# root is the parent window for this user interface
proc adatbe_ui {root args} {
# this treats "." as a special case
if {$root == "."} {
set base ""
} else {
set base $root
}

label $base.label#1 \
-text El?gyártmány:
catch {
$base.label#1 configure \
-font -*-Helvetica-Bold-R-Normal-*-*-140-*-*-*-*-*-*
}

entry $base.entry#1 \
-highlightthickness 2 \
-textvariable Stock \
-width 25
catch {
$base.entry#1 configure \
-font -*-Helvetica-Medium-R-Normal-*-*-140-*-*-*-*-*-*
}
checkbutton $base.checkbutton#1 \
-command {.entry#2 configure –background white} \
-text Elektróda \
-textvariable textvar \
-variable elektrode
label $base.label#2 \
-text Nullpont:
catch {
$base.label#2 configure \
-font -*-Helvetica-Bold-R-Normal-*-*-140-*-*-*-*-*-*
}
entry $base.entry#2 \
-background grey \
-highlightthickness 2 \
-selectbackground grey \
-state disabled \
-textvariable MCS0
catch {
$base.entry#2 configure \
-font -*-Helvetica-Medium-R-Normal-*-*-140-*-*-*-*-*-*
}
button $base.button#2 \
-command exit \
-text ESC

button $base.button#3 \
-command {set MCSorigin .MCS0; set stock .stock; exit} \
-padx 210 \
-text OK
# Geometry management
grid $base.label#1 -in $root -row 1 -column 1 \
-sticky e
grid $base.entry#1 -in $root -row 1 -column 2 \
-columnspan 2 \
-sticky ew
grid $base.checkbutton#1 -in $root -row 2 -column 1
grid $base.label#2 -in $root -row 2 -column 2 \
-sticky e
grid $base.entry#2 -in $root -row 2 -column 3 \
-sticky ew
grid $base.button#2 -in $root -row 3 -column 1
grid $base.button#3 -in $root -row 3 -column 2 \
-columnspan 2
# Resize behavior management
grid rowconfigure $root 1 -weight 0 -minsize 1
grid rowconfigure $root 2 -weight 0 -minsize 30
grid rowconfigure $root 3 -weight 0 -minsize 30
grid columnconfigure $root 1 -weight 0 -minsize 28
grid columnconfigure $root 2 -weight 0 -minsize 30
grid columnconfigure $root 3 -weight 0 -minsize 400
# additional interface code
# end additional interface code
}
# Allow interface to be run "stand-alone" for testing
catch {
if [info exists embed_args] {
# we are running in the plugin
adatbe_ui .
} else {
# we are running in stand-alone mode
if {$argv0 == [info script]} {
wm title . "Testing adatbe_ui"
adatbe_ui .
}
}
}
it looks fine, but not works...my software's integrated tcl shell may not understand... :confused:
 
According to the Tclrs Wiki at SpecTcl is a GUI editing program. Is that what you want? Are you building an application and using SpecTcl to build it or are you trying to change SpecTcl to be your application? If the latter, what is it you want your application to do?

_________________
Bob Rashkin
rrashkin@csc.com
 
It didn't work for me either. It looks more complicated than it needs to be for 2 labels, 2 entries, 2 buttons, and a checkbutton. I admit that I have consistently had trouble getting "grid" geometry to do what I want; I much prefer "pack". Also, your script doesn't appear to do much, even if it did work. What do you want it to do?

Anyway, try this:
Code:
#top frame for various widgets
pack [frame .ftop -borderwidth 4] -side top
set w .ftop
label $w.l1 -text El?gyártmány: -font -*-Helvetica-Bold-R-Normal-*-*-140-*-*-*-*-*-*
grid $w.l1 -row 1 -column 1
entry $w.e1 -width 25 -textvariable Stock
grid $$w.e1 -row 1 column 3
checkbutton $w.cb1 -command {.ftop.e2 configure -background white} -text Electroda -variable electrode
grid $w.cb1 -row 2 -column 1
label $w.l2 -text Nullpoint: -font -*-Helvetica-Bold-R-Normal-*-*-140-*-*-*-*-*-*
grid $w.l2 -row 2 -column 2
entry $w.e2 -textvariable MCSO
grid $w.e2 -row 2 -column 3
button $w.b1 -text ESC -command exit
button $w.b2 -text OK -command {set MCSorigin .MCSO; set stock .stock; exit}
grid $w.b1 -row 3 -column 1
grid $w.b2 -row 3 -column 2

As near as I can tell, this does the same thing (no more) as your script.


_________________
Bob Rashkin
rrashkin@csc.com
 
the added code is almost nothing, set variables, and close window...
i will try your code...tomorrow..
..and thanks
 
there is a chechbutton, and next to it an entry box.
i want that if the checkbox is set on, set the entry box state to 'disabled', and write to the entry box a default text..and if the checkbox is set off again, restore the original state..
and there is other thing too: how can i read the string of the checkbox into a variable?
 
change
checkbutton $w.cb1 -command {.ftop.e2 configure -background white} -text Electroda -variable electrode
to
checkbutton $w.cb1 -command [red]{cbcmd $electrode}[/red] -text Electroda -variable electrode,
change the entry widget definition to
entry $w.e1 -width 25 -textvariable Stock [red]-disabledbackground white[/red]
and add this proc:

proc cbcmd {electrode} {
if {$electrode == 1} {
.ftop.e2 configure -state disabled
set ::Stock "default text"
} else {
.ftop.e2 configure -state normal
set ::Stock ""
}
}


To read the string of the checkbox into a variable, I assume you mean the -text option setting, "Electroda". Try:
set tvar [.ftop.cb1 cget -text]

_________________
Bob Rashkin
rrashkin@csc.com
 
the "-disabledbackground white" produce an error :-?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top