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!

radio button remembers it's previous prompts

Status
Not open for further replies.

Paul1970

Programmer
Sep 17, 2008
7
CA
I've created a radio button which gets prompted when posting a program in Unigraphics.

How can I modify this so that the radio button remembers it's previous settings from a previous prompting?

I hope this makes sense.


Thanks,
Paul Perry

The below code is for my radio button:


wm title . " HAAS MASTER POST "
############################################################
proc bldORpattern { parent varname args } {

set i [frame $parent.cst_pat -borderwidth 2 ]
set b 0
foreach item $args {
radiobutton $i.$b -variable $varname \
-text $item -value $item
pack $i.$b -side left
incr b
}
pack $i -side top -pady 7 -anchor w -fill x
}
############################################################
proc Probing { parent varname args } {

set j [frame $parent.probing -borderwidth 2 ]
set b 0
foreach item $args {
radiobutton $j.$b -variable $varname \
-text $item -value $item
pack $j.$b -side left
incr b
}
pack $j -side top -pady 7 -anchor w -fill x
}
############################################################
proc Fixtures { parent varname args } {

set f [frame $parent.choices -borderwidth 2 ]
set b 0
foreach item $args {
radiobutton $f.$b -variable $varname \
-text $item -value $item
pack $f.$b -side left
incr b
}
pack $f -side top -pady 7 -anchor w -fill x
}
############################################################
proc ShowChoices { parent varname args } {
set g [frame $parent.side -borderwidth 2 ]
set b 0
foreach item $args {
radiobutton $g.$b -variable $varname \
-text $item -value $item
pack $g.$b -side left
incr b
}
pack $g -side top -pady 7 -anchor w -fill x
}
############################################################
proc ShowHand { parent varname args } {
set h [frame $parent.hand -borderwidth 2 ]
set b 0
foreach item $args {
radiobutton $h.$b -variable $varname \
-text $item -value $item
pack $h.$b -side left
incr b
}
pack $h -side top -pady 7 -anchor w -fill x
}
############################################################
set cst_pat "Machining_Propellers"
bldORpattern {} cst_pat "Machining_Propellers" "Machining_Patterns"

set probing "Probe_Propellers "
Probing {} probing "Probe_Propellers " "Probe_Patterns"

set choice "18-28_Fixture "
Fixtures {} choice "18-28_Fixture " "29-36_Fixture " "5Blade_Fixture"

set side "Pressure_Side "
ShowChoices {} side "Pressure_Side " "Suction_Side"

set hand "Right_Hand "
ShowHand {} hand "Right_Hand " "Left_Hand"

############################################################
pack [ button .b2 -text Done -padx 25 -pady 5 -command Writoe ] -side bottom -padx 20 -pady 10
###########################################################


proc Writoe {} {

global cst_pat
global probing
global choice
global side
global hand




puts $cst_pat
puts $probing
puts $choice
puts $side
puts $hand

set l_return [list $cst_pat $probing $choice $side $hand]
puts $l_return


exit
}



 
I think you'll be ok if you make varname a global.

_________________
Bob Rashkin
 
Thanks for the reply unfortunelty I wasn't able to get this working.

Kind regards,
Paul Perry
 
Is it your intention that each radiobutton set in the separate procs (Probing, Fixtures, etc.) have different variables? If so, you will need to make them separate global variables. I'd also recommend against passing in the variable name as an argument. That's always a problem.

_________________
Bob Rashkin
 
Hi Bong,

My main objective is to have a radio button in which everytime a user uses it, the button remembers it's previous selections from a previous prompting.

If possible would you show me a simple working example if possible? :)




Thanks,

Paul Perry
 
What do you mean by "prompting"?

Here is some code that does 3 tiers of radio buttons:
Code:
#radio button example
proc mkfrms {nf1 nf2} {
     for {set i 0} {$i<$nf1} {incr i} {
         pack [frame .$i -borderwidth 4] -side top
         for {set j 0} {$j<$nf2} {incr j} {
             pack [frame .$i.$j -borderwidth 4] -side left
         }
     }
}
mkfrms 3 3
set w .0.0
pack [radiobutton $w.r1 -variable var1 -value "value 1" -text "val-1"] -side top
pack [radiobutton $w.r2 -variable var1 -value "value 2" -text "val-2"] -side top
pack [radiobutton $w.r3 -variable var1 -value "value 3" -text "val-3"] -side top
pack [radiobutton $w.r4 -variable var1 -value "value 4" -text "val-4"] -side top
set var1 "value 1"
set w .0.1
pack [radiobutton $w.r1 -variable var2 -value "value 1" -text "val-1"] -side top
pack [radiobutton $w.r2 -variable var2 -value "value 2" -text "val-2"] -side top
pack [radiobutton $w.r3 -variable var2 -value "value 3" -text "val-3"] -side top
pack [radiobutton $w.r4 -variable var2 -value "value 4" -text "val-4"] -side top
set var2 "value 2"
set w .0.2
pack [radiobutton $w.r1 -variable var3 -value "value 1" -text "val-1"] -side top
pack [radiobutton $w.r2 -variable var3 -value "value 2" -text "val-2"] -side top
pack [radiobutton $w.r3 -variable var3 -value "value 3" -text "val-3"] -side top
pack [radiobutton $w.r4 -variable var3 -value "value 4" -text "val-4"] -side top
set var3 "value 3"
set w .1.0
pack [label $w.l1 -text "value of var1:"] -side top
pack [label $w.l2 -text "value of var2:"] -side top
pack [label $w.l3 -text "value of var3:"] -side top
set w .1.1
pack [entry $w.e1 -textvariable var1] -side top
pack [entry $w.e2 -textvariable var2] -side top
pack [entry $w.e3 -textvariable var3] -side top

The 3 variables (un-artfully named: var1, var2, and var3] are set by choosing a radio button in each of the 3 tiers.

Now, what behavior are you looking for? Note that if you want the script to remember the values from a previous time the script was run, you'll have to write them out to a file and read them in for initialization.

_________________
Bob Rashkin
 
You wrote:

"if you want the script to remember the values from a previous time the script was run, you'll have to write them out to a file and read them in for initialization."



This is exactly what i want to do... but I'm only a beginner in programming.... not sure how to go about this.

I tried looking for a working example of this so i could play around with to fully understand the logic behind it.

I read chapter 45 in the book "Practical Programming in TCL and TK" ... Brent B. Welch, Ken Jones.

I think that might relate to what i want to achieve. But I'm just not at that level to fully understand the full scope of this chapter.




Kind regards,

Paul Perry
 
Let's say you have, oh I don't know, 5 sets of radiobuttons. That means that there are 5 separate variables, let's call them var1 through var5, whose values are controled by the 5 sets of radiobuttons. Each radiobutton in each set assigns a specific value to its variable.

Now suppose you have a text file, call it "values.txt". Each line of this file (and there will be 5 lines) contains 2 items separated by a comma. These will be the initial values for each of the 5 variables. So, line 1 of the file might say var1,42, or something.

Then, when your script starts, just after building all the windows, you read the file and populate the variables:
Code:
set fid [open values.txt r]
set lstLines [split [read $fid] \n]
close $fid
foreach l $lstLines {
  set lstPairs [split $l ,]
  set [lindex $lstPairs 0] [lindex $lstPairs 1]
}

Then, before exiting, you do it in reverse:
Code:
set fid [open values.txt w]
foreach v {var1 var2 var3 var4 var5} {
  puts $fid $v,[subst $$v]
}
close $fid

_________________
Bob Rashkin
 
Bong you are a guru in programming! It works!!! I'm feeling very giddy right now as i've spent many hours trying to aclomplish this.

Thank you so much! I'm very grateful!

Yours sincerely,

Paul Perry


 
Hi

Here on Tek-Tips we used to thank for the received help by giving stars. Please click the

* [navy]Thank Bong
for this valuable post![/navy]


at the bottom of Bong's post. That way you both show your gratitude and indicate this thread as helpful.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top