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

how to pack items on same line in frame

Status
Not open for further replies.

judyj

Programmer
Oct 15, 2002
4
US
I am new to Tcl/TK and am trying to build a GUI with two frames The first frame is a text frame to view files, and a second frame of config options. They will both be visible all the time with one on the right, and the other on the left. I can build the pieces separately, but am having trouble putting them together. For instance, how do you tie a label and an entry to the same line. I tried using various pack options with no luck. Do I need to imbed frames within a frame? For example, I have a list box and a scrollbar in the example below. I cannot get them to be tied to each other. Should I define a separate frame for each group of widgets I want to tie together?


#!/bin/sh
#exec wish "$0" "$@"

menu .menubar -type menubar
.menubar add cascade -label File -menu .menubar.file -underline 0

#file menu
menu .menubar.file -tearoff 0
.menubar.file add command -label "New" -underline 0 -command { new }
.menubar.file add command -label "Open..." -underline 0 -command { file_get }
.menubar.file add command -label "Save" -underline 0 -command { save }
.menubar.file add command -label "Save As..." -underline 5 -command { file_save_as }
.menubar.file add separator
.menubar.file add command -label Exit -underline 1 -command { exit }
#end file menu

. configure -menu .menubar


#
# Define a frame widget to hold config parameters
# Note: possibly call this from a "configure button"
#
frame .config
label .config.repLabel -text "Report:"
tk_optionMenu .config.repNames repOption "History Report" "Snapshot Report" "Operator Report" pack .config.repLabel .config.repNames
label .config.timeLabel -text "Start Time:"
entry .config.strtDateTime -width 40 -textvariable repStrtTime
entry .config.stopDateTime -width 40 -textvariable repStopTime
entry .config.histDateTime -width 40 -textvariable repHistTime
pack .config.timeLabel .config.strtDateTime
button .config.button2 -text "Generate Report" -command { gen_report $repOption $repStrtTime $repStopTime $repHistTime }
scrollbar .config.scroll -command ".config.list yview"
listbox .config.list -yscroll ".config.scroll set" -setgrid 1 -height 10
pack .config.timeLabel .config.strtDateTime .config.stopDateTime .config.histDateTime -side top -anchor w -pady 5 -padx 10
pack .config.button2 -side bottom -expand yes
pack .config.scroll -side right -fill y
pack .config.list
pack .config -fill x

.config.list insert 0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z AA BB CC DD EE FF GG HH

set filename "Untitled"

frame .text
text .text.t -wrap none -yscrollcommand ".text.v_scroll set" -xscrollcommand ".text.h_scroll set"

scrollbar .text.v_scroll -command ".text.t yview"
scrollbar .text.h_scroll -command ".text.t xview" -orient horizontal
pack .text.v_scroll -side right -fill y
pack .text.h_scroll -side bottom -fill x
pack .text.t -side left -fill both -expand 1
pack .text -fill both -expand 1


#
# Procedure definitions
#
 
For your need I prefere to use grid.
grid permits to place widgets inside a grid with rows & columns.

Your code revisited with grid:
Code:
#!/bin/sh
#exec wish "$0" "$@"
 
 menu .menubar -type menubar
 .menubar add cascade -label File -menu .menubar.file -underline 0

 #file menu
 menu .menubar.file -tearoff 0
 .menubar.file add command -label "New" -underline 0  -command { new }
 .menubar.file add command -label "Open..." -underline 0  -command { file_get }
 .menubar.file add command -label "Save" -underline 0  -command {  save }
 .menubar.file add command -label "Save As..." -underline 5  -command { file_save_as }
 .menubar.file add separator
 .menubar.file add command -label Exit -underline 1 -command { exit }
 #end file menu
 
 . configure -menu .menubar


#
# Define a frame widget to hold config parameters
# Note: possibly call this from a "configure button"
#
 frame .config
 label .config.repLabel -text "Report:"
 tk_optionMenu .config.repNames repOption  "History Report" "Snapshot Report" "Operator Report"
 
 label  .config.timeLabel -text "Start Time:" 
 entry  .config.strtDateTime -width 40 -textvariable repStrtTime
 entry  .config.stopDateTime -width 40 -textvariable repStopTime
 entry  .config.histDateTime -width 40 -textvariable repHistTime
 button .config.button2 -text "Generate Report"     -command { gen_report $repOption $repStrtTime $repStopTime $repHistTime }
 scrollbar .config.scroll -command ".config.list yview"
 listbox .config.list -yscroll ".config.scroll set" -setgrid 1 -height 10 

 grid .config.repLabel      -row 0 -column 0
 grid .config.repNames      -row 0 -column 1
 grid .config.timeLabel     -row 1 -column 0
 grid .config.strtDateTime  -row 1 -column 1 -pady 5 -padx 10
 grid .config.stopDateTime  -row 2 -column 1 -pady 5 -padx 10
 grid .config.histDateTime  -row 3 -column 1 -pady 5 -padx 10
 grid .config.list          -row 0 -column 2 -rowspan 4
 grid .config.scroll        -row 0 -column 3 -rowspan 4 -sticky ns
 grid .config.button2       -row 4 -column 0 -columnspan 4 -pady 10

 .config.list insert 0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z AA BB CC DD EE FF GG HH

 set filename "Untitled"

 frame .text
 text .text.t -wrap none  -yscrollcommand ".text.v_scroll set"  -xscrollcommand ".text.h_scroll set"

 scrollbar .text.v_scroll -command ".text.t yview"
 scrollbar .text.h_scroll -command ".text.t xview" -orient horizontal
 grid .text.t         -row 0 -column 0
 grid .text.v_scroll  -row 0 -column 1 -sticky ns
 grid .text.h_scroll  -row 1 -column 0 -sticky ew

 grid .config -row 0 -column 0 -sticky ew
 grid .text   -row 1 -column 0 -sticky nsew


#
# Procedure definitions 
#

Good luck

ulis
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top