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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reloading(?) radiobuttons & variables

Status
Not open for further replies.

godatguitar

Programmer
May 8, 2003
33
0
0
GB
OOps, forgot i have another question that has been bugging me:

My project is a multiple choice test using radiobuttons:
When a button (submit) is pressed at the bottom of the page, i want the radiobuttons to "HIGHLIGHT" the correct answers, ie modify the text to change colour or something easy to see.
I set the variables to the radiobuttons to the correct values, then what do i do? Do i have to repack the individual questions that are in seperate frames?

Many thanks

 
Each radiobutton has its own name. Have a list of the correct ones. Then use:
<RBname> configure -fg red
(or whatever color you want)

Bob Rashkin
rrashkin@csc.com
 
Excellent. Cheers.....

One other thing, my radiobuttons are called:
$f.r1, $f.r2 ....etc

as they are in frames. To access these from outside the proc, do i have to declare the frame as global??
 
One other thing,

i have a list of code:
set q1 0
set q2 3
set q4 5....


can i do this all on 1 line? If so how?
Its not set q1 0 q2 2, just a syntax thing i gotta do i presume?

Cheers
 
The frames are by definition global, so that's not a problem. You really can't set all the variables on 1 line unless there is some algorithm whereby q$i = &quot;f(i)&quot;. That case you can use &quot;foreach ...&quot;. That said, you can keep the variable names and correct values in an array (or ordered list) and use a loop to set them (that's what I would do).

Bob Rashkin
rrashkin@csc.com
 
I cannot access the frames from outside the proc:

Basically, all my frames are called $f, and as they are all in different procs, this doesnt matter. (does it?)

Outside the procs, i want to access the frames maybe like:

$f.r1 configure -fg red.

This i want to turn radiobutton .r1 in the frame red.

This does not work, so where am i going wrong?

Cheers
 
You need to access the frames by their real names. They're not called &quot;$f&quot;, they're called whatever &quot;$f&quot; expands to. Presumably, you set them with a &quot;frame .abc.xyz ...&quot; kind of statement. Then you &quot;set f .abc.xyz&quot; or something like that. You need to refer to the frames by what &quot;f&quot; is set to in each instance.

Bob Rashkin
rrashkin@csc.com
 
Hi again

Here is the code from the beginnning of the program where the frame is made etc, and then the beginning of the other proc that uses a frame inside of that one.
I am confused on how to access/modify the colour of the text on say, .r1 radiobutton. I want to do:
.r1 configure -fg red.

But need the frame name, and i am not sure what to use.
Cheers


proc ScrollableFrame {w} {

frame $w
canvas $w.c -height 600 -width 420 -xscrollcommand [list $w.xbar set] -yscrollcommand [list $w.ybar set]
scrollbar $w.xbar -orient horizontal -command [list $w.c xview]
scrollbar $w.ybar -orient vertical -command [list $w.c yview]

frame $w.c.contents

$w.c create window 0 0 -anchor nw -window $w.c.contents

grid $w.c -row 0 -column 0 -sticky nsew -pady 4 -padx 2
grid $w.ybar -row 0 -column 1 -sticky ns -pady 4 -padx 2
grid $w.xbar -row 1 -column 0 -sticky ew -pady 4 -padx 2
grid columnconfigure $w 0 -weight 1
grid rowconfigure $w 0 -weight 1

bind $w.c.contents <Configure> [list UpdateCanvas $w.c]

return $w
}

proc UpdateCanvas {c} {
$c configure -scrollregion [$c bbox all]
}

set frameCounter 0

proc Question1 {parent} {

global frameCounter
set i [incr frameCounter]
set f [frame $parent.f$i -bd 2 -relief groove]
message $f.m -text &quot;1.) What is the relationship between Avo and Ais?&quot; -width 400
radiobutton $f.r1 -text &quot;Avo = Ais.Ro/Ri&quot; -variable q1 -value 0



Cheers in advance

 
If I understand your problem, the main program calls &quot;ScrollableFrame&quot; and passes it the name of the frame into which the canvas is created. Then, somewhere else, you want to change the configuration of the widgets in the frame. As I see it, you have 2 choices:

1. You can go into the main program and find out the real name that is passed into ScrollableFrame. Alternatively (I guess this makes it 3 choices but I think's it's more like a corollary) you can change ScrollableFrame to return the name of the frame (or the canvas) and keep that as a separate variable.

2. You can call the configuration change from inside one of the proc's where you have a local variable for the frame name, passing it along as an argument

Bob Rashkin
rrashkin@csc.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top