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!

frame height and width 3

Status
Not open for further replies.

stewang

Programmer
Aug 21, 2003
77
NZ
Hello all:
I try to set up a frame with height and width both 500, I failed for that. when I run my code, I can not see the frame with height and width are both 500,would anyone help me,please.

Code:
frame .menuframe -bg white  -height 500 -width 500

menubutton .menuframe.org  -text "Organise Item" -menu .menuframe.org.menu
menubutton .menuframe.acc  -text "Aceess" -menu .menuframe.acc.menu

menu .menuframe.org.menu
menu .menuframe.acc.menu

.menuframe.org.menu add command -label "Open..." 
.menuframe.org.menu add command -label "Save..." 

pack .menuframe -side top -fill x -expand yes
pack .menuframe.org -side left
pack .menuframe.acc -side left
 
I've noticed this, too, in the past. I think height and width on a frame are dynamic. Since you only put menubuttons in the frame, it's only as big as it needs to be for them. If you add, say, a text widget to the same frame, it will be big enough for that. Since a standard Tk frame is not scrollable, it doesn't make sense for it to be a size other than what is needed for the children.

Bob Rashkin
rrashkin@csc.com
 
The standard behavior of frames and toplevels when using pack and grid is to "shrinkwrap" as tightly as possible around their contents without actually squashing the contents. In other words, the contents of a frame or toplevel determines its size. (Unless the window manager overrides that preference -- either because the "preferred" size of the window is too large for display or because the user manually resized the window.)

This is usually the desired behavior. It usually doesn't look very good to have some widgets floating in a sea of empty space. And if all you want is a little extra margin around some of the widgets, simply use the -padx and -pady options when you pack or grid the widgets. And I suspect that this is the case in your example, as when you pack the frame, you're packing it with -expand yes and -fill x, which is explicitly telling pack that you want to override the default size of the indicated widget. (As an aside, you really don't want the -expand yes is this example. The -fill x accomplishes your goal of causing the frame to fill its packing space horizontally.)

In those rare situations where you really do want to fix the size of a frame (or labelframe), you need to tell pack or grid not to "propagate" the geometries of the children to the containing frame. If you're using pack, turn off propagation with:

Code:
pack propagate .menuframe 0

If you're using grid, turn off propagation with:

Code:
grid propagate .menuframe 0

As another aside, I notice that you're using the old technique for creating a menubar. This method has been obsolete since Tcl/Tk 8.0 (which also introduced native menubar support on Macintosh and Windows platforms). Although your approach still works, the preferred method is as follows:

Code:
# Create a menu widget to act as the window's menubar

menu .mbar

# Associate the menu as the window's menubar

. configure -menu .mbar

# Create a couple of submenus, disabling the "tear-off"
# feature on each of them.

menu .mbar.org -tearoff 0
menu .mbar.acc -tearoff 0

# Add them to the menubar, providing "Alt-style" keyboard
# accelerators simply by indication which character in
# the label to underline.

.mbar add cascade -label "Organise Item" -underline 0     -menu .mbar.org
.mbar add cascade -label "Access" -underline 0     -menu .mbar.acc

# Add some commands to the "Organise Item" menu. Are you
# sure you don't want to call this "File" like most other
# applications?

.mbar.org add command -label "Open..." -underline 0     -command {openFile}
.mbar.org add command -label "Save..." -underline 0     -command {saveFile}

For more information on menus, you might want to check out the Tcl'ers Wiki ( perhaps starting with the page "menu," and then continuing to some of the other menu-related pages as found by this search,
- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Code:
Hi Bong:
Thanks for your respone. But I still got a question to ask you .
why I set up a frame with height and width, but without another wedget, it bring out a window with desired width and height.


1> This is the code I write.
frame .frame1 -background white -height 300 -width 50
pack .frame1 -fill both -expand yes


2> you are right, when I put a text wedget with width and height into frame, it will big enought for that.  

frame .menuframe -bg white  -height 500 -width 500
label .menuframe.lb -text "test"
text  .menuframe.t -height 50 -width 50

menubutton .menuframe.org  -text "Organise Item" -menu .menuframe.org.menu
menubutton .menuframe.acc  -text "Aceess" -menu .menuframe.acc.menu

menu .menuframe.org.menu
menu .menuframe.acc.menu

.menuframe.org.menu add command -label "Open..." 
.menuframe.org.menu add command -label "Save..." 

pack .menuframe -side top -fill x -expand yes
pack .menuframe.org -side left
pack .menuframe.acc -side left
pack .menuframe.t -side bottom
pack .menuframe.lb  -side bottom

pack .menuframe
 
Hello Avia:
Thanks for your time, I tested pack and grid, they can work.
And also thanks for your coding for menubar. I will need some function
call this "File" like most other applications, but I am going to do by myself first.

Thanks again.

rgds
stewang
 
It's like shrink-wrap. You start out with a sheet, but when you put something in it, that's the size it takes.

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

Part and Inventory Search

Sponsor

Back
Top