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

Loading BWidgets library

Status
Not open for further replies.

godatguitar

Programmer
May 8, 2003
33
GB
Hi

I am very new to tcl, as you are prob aware due to my previous posts! LOL :)

Anyway, I have been trying to build a scrollable window in which i can place some radiobuttons and labels/messages for a test type-thing.(LOL) I intend to group the radiobuttons together so that the user can chose 1 option only, and then submit his answers, gaining a result at the end.
I am trying to use visual tcl to write the program, as i am not that good at writing the code yet. It seems very hard....

Basically, I need a scrollable window/frame that will do the trick, so i can then place the widgets (such as radiobuttons etc) IN the window/frame, that can then scroll vertically ONLY.

I have had no luck using the BWidget library as i understand there is a scrollable widget in it, but visual tcl is unable to load it.

Does anyone have anycode (from scratch) that i can copy/paste into a program for me to use? I only need the scrollable window/frame to open once the tcl file is opened.

Any help would be great, as i am pulling my hair out over this.

Thanks all in advance :)
 
I haven't used Bwidgets but this might do what you want (using a text widget):
Code:
proc mkframes {{n 5}} {
     for {set i 1} {$i<=$n} {incr i} {
	    pack [frame .$i -borderwidth 2 -relief groove] -side top
	         for {set j 1} {$j<=$n} {incr j} {
		        pack [frame .$i.$j -borderwidth 4] -side left
		    }
	}
}
mkframes 2
set w .1.1
text $w.t -width 80 -height 20 -yscrollcommand &quot;$w.s set&quot;
scrollbar $w.s -command &quot;$w.t yview&quot;
pack $w.s -side right -fill y
pack $w.t -side left
set w .1.1.t
$w insert end &quot;Whenever I want to use scrollbars, I use a text widget.
          I know there are Bwidgets and Iwidgets that do more fancy stuff but
          I've never used them.\n\n&quot;
$w insert end &quot;Here's a sample test question:\n\nWhat is the right answer?\n&quot;
foreach ans {0 10 12 4i 42} {
        radiobutton $w.$ans -text $ans -variable answer -value $ans
        $w window create end -window $w.$ans
}
$w insert end \n
$w insert end &quot;now let's just propagate this to show the scrollbar working\n&quot;
for {set i 0} {$i<30} {incr i} {
    $w insert end &quot;What is the right answer?\n&quot;
    foreach ans {10 12 4i 42} {
        radiobutton $w.$i$ans -text $ans -variable answer_$i -value $ans
        $w window create end -window $w.$i$ans
    }
    $w insert end \n
}

Bob Rashkin
rrashkin@csc.com
 
Thanks for the help.

This is close to what i want, but the text displayed must not be able to be edited, ie state disabled, and the radiobuttons must be in groups of 4 vertically.

What would i have to do to sort this out?
Many thanks again. I usually use visual tcl, but i cant import this or source this file as visual tcl is, in my opinion, rather useless to me, as i cant seem to get any other code imported correctly.
Is it possible to place widgets into the scrollable text, such as buttons etc like you have done, and get them to scroll? i cant do it in visual tcl at all. i think its to do with getting the widget to not be a child of the scrollable window, i am not positive though.

Any help would be great.
Many thanks
 
A hacked srolledframe package:

To use it:
1/ download it
2/ put it in the directory where is you script
3/ add to your script:
Code:
  source scrolledframe.tcl
  package require Scrolledframe
  namespace import ::scrolledframe::scrolledframe
  scrolledframe .sf -height 150 -width 100 -yscroll {.sb set}
  scrollbar .sb -command {.sf yview}
  pack .sf -side left -fill both -expand 1
  pack .sb -side left -fill y -expand 1
  set f .sf.scrolled
  # add what you want to $f
  # example:
  foreach i {0 1 2 3 4 5 6 7 8 9}   { 
    label $f.l$i -text &quot;scrolled label $i&quot; -relief groove
    pack $f.l$i
  }

HTH

ulis
 
Ulis' solution is, as usual, superior. However, if you're still interested in the questions you asked about using the scrolled text widget:

1. As you say, add &quot;-state disabled&quot; to the text definition and your users will not be able to add text

2. After each &quot;$w window create end -window $w.$ans&quot; add a line, &quot;$w insert end \n&quot;

3. You can put any buttons you want in the text with &quot;$w window create <position> -window <widget name>&quot;. You might find the code in the widget demo interesting. Assuming you installed from ActiveState, there should be a package of demos for Tk. You should look at &quot;A text widget with embedded windows&quot;. If you're on Windows, it should be under ...\tcl\demos\tk\twind.tcl.

BTW, I never had any luck with vtcl and abandoned it pretty quickly. I use a text editor; saves me grief.


Bob Rashkin
rrashkin@csc.com
 
Correction:
You can't put the &quot;-state disabled&quot; statement in the widget definition as that would make it impossible to insert the text. Instead, after the text is all done add the statement, &quot;$w configure -state disabled&quot;.

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

Part and Inventory Search

Sponsor

Back
Top