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!

Problem using winfo

Status
Not open for further replies.

gr8oblivion

Programmer
Jul 6, 2004
1
CA
Hey,

I'm new to tcl/tk, and am trying to something relatively simple (I would assume)

essentially i have "nested" frames and I want the inner frame be centered inside the bigger outer/master frame... here's my code fragment:

frame .main.inner -borderwidth 2 -relief raised

set entryone ""
set entrytwo ""

label .main.inner.alabel -text "label"
pack .main.inner.alabel -in .main.inner

update

pack .main.inner -in .main -padx [expr ([expr [.main cget -width] - [winfo width .main.inner]] / 2)] -padx [expr ([expr [.main cget -height] - [winfo height .main.inner]] / 2)]


BUT, the winfo procedures both return "1" as the width/height of the .main.inner frame, even after i explicitly call "update" -- also, when i tried to use reqwidth/reqheight instead of height/width i still got "1" as the value...

What am i doing wrong?

Thanks in advance
 
How have you specified the outer .main frame? It's not listed in your code.
There is a typo as you have two padx options and I think your formula can be simplified to,

pack .main.inner -in .main -padx [expr [.main cget -width] - [winfo width .main.inner] / 2] -pady [expr [.main cget -height] - [winfo height .main.inner] / 2]

The outer frame gets resized to take up empty space, to de-activate this add,

pack propagate .main false

the pack manager can be a git to sort out. Can you achieve what you want any easier using grid?
 
Bong posted this as a response to one of my questions, it occured to me that this might be what you want ...

The 'place' command (instead of pack or grid)

SYNOPSIS
place window option value ?option value ...?
place configure window ?option? ?value option value ...?
place forget window
place info window
place slaves window


DESCRIPTION
The placer is a geometry manager for Tk. It provides simple fixed placement of windows, where you specify the exact size and location of one window, called the slave, within another window, called the master. The placer also provides rubber-sheet placement, where you specify the size and location of the slave in terms of the dimensions of the master, so that the slave changes size and location in response to changes in the size of the master. Lastly, the placer allows you to mix these styles of placement so that, for example, the slave has a fixed width and height but is centered inside the master.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top