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

Placing a scrollbar in a toplevel window

Status
Not open for further replies.

satguy

Programmer
Jun 30, 2005
6
US
In my application I have a single frame that contains some entries and three buttons. One of the buttons is labeled "Help". Here's what I'd like to do. When the user pushes "Help", another window will pop up displaying the help text. I have been able to do this using a procedure called help_file. It spawns a new window using 'toplevel' and the help message as text using 'message'. I want to be able to add a scrollbar to this new 'Help' window and can't seem to get the code right to do it. Here's a general form of the code I am working with. Any help would be appreciated.

Thanks.

#!/bin/sh
#The next line executes wish - wherever it is exec wish "$0" "$@"
#-----------------------------------------------------
# Define main window frame widget
#
proc createMainWindow { } {
global ft
set ft "arial 12 bold"
set ft1 "arial 18 bold"
#
# Create the main frames
#
frame .fMain -relief groove -borderwidth 5 -background grey
frame .fOK -relief groove -borderwidth 5 -background grey
frame .fTop -relief groove -borderwidth 5 -background grey
#
# Define entries and labels for userid and passwords
#
label .lID -text "\nEnter ID:" -font $ft -background grey
entry .eID -validate key -vcmd { expr {[string is ascii %P] && [string length %P] <11 }} -background white -font $ft -width 18 -justify center -highlightthickness 2
#
# Pack the frames and labels
#
pack .fTop .fMain .fOK -side top -fill x -ipady 10
pack .lID .eID -in .fMain
#
# Focus user on 1st entry window
#
focus .eID
}
#===================================================
proc write_file { } {
global ft
set userid [.eID get]
set str [string length "$userid get"]
#

frame .fSub -borderwidth 5 -relief groove -background grey
button .bCancel -text "CANCEL" -command { desThisWindow } -borderwidth 4 -font $ft -background grey
pack .fSub -ipady 10 -fill x
bind .bCancel <Return> { desThisWindow }

if { $userid == "" || $str >= 15 } {
label .lSub -text "\nIncorrect user ID.\n\nHit Cancel and try again.\n" -font $ft -width 28 -background grey
pack .lSub .bCancel -in .fSub
}
}
#====================================================
# Main Program
#====================================================
proc main { } {
createMainWindow
}
main
#====================================================
# Help window
#====================================================
proc help_file { } {
toplevel .help
global ft
set ft "arial 12 bold"
frame .help.fMain -relief groove -borderwidth 5 -background grey80
message .help.msg -aspect 1000 -justify left -background grey80 -relief raised -fg blue -padx 140 -text "\nHELP FILE\n"
pack .help.fMain
pack .help.msg -in .help.fMain
button .help.bExit -text "Exit" -bg grey -borderwidth 2 -font $ft -padx 100 -pady 10 -command { focus .eID; destroy .help }
pack .help.bExit -in .help.fMain -padx 5 -pady 5 -fill x
bind .help.bExit <Return> { focus .eID }
}
#=====================================================
# Define button widgets.
#=====================================================
button .bOK -text "OK" -background grey -borderwidth 4 -font $ft -padx 20 -pady 10 -command { write_file; unable}
pack .bOK -in .fOK -padx 5 -pady 5 -expand true
bind .bOK <Return> { write_file; unable }
#
button .bExit -text "Exit" -background grey -borderwidth 4 -font $ft -padx 20 -pady 10 -command { desThisWindow }
pack .bOK .bExit -in .fOK -side left -padx 5 -pady 5 -expand true
bind .bExit <Return> { desThisWindow }
#
button .bHelp -text "Help" -background grey -borderwidth 4 -font $ft -padx 20 -pady 10 -command { help_file }
pack .bOK .bExit .bHelp -in .fOK -side left -padx 5 -pady 5 -expand true
bind .bHelp <Return> { help_file }

#===================================================
proc desThisWindow { } {
destroy .
}
#===================================================
# unable the entries
#===================================================
proc unable { } {
.bOK configure -state disabled;
.bExit configure -state disabled;
.bHelp configure -state disabled;
.eID configure -state disabled;
focus .bCancel
}
 
I think you can't scroll a frame or a window, unless you use BWidgets (ScrollableFrame or ScrolledWindow). In vanilla Tk, you have to use a 'text' widget and attach a scrollbar to it.

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

Part and Inventory Search

Sponsor

Back
Top