[Tkinter-discuss] question on winfo_height

Bryan Oakley bryan.oakley at gmail.com
Wed Apr 10 17:20:35 CEST 2013


winfo_height returns the actual, absolute height of the window. It's
not relative to anything.

The reason the value is 1 is because the frame has yet to be displayed
on the screen. It is the actual updating of the screen that gives a
widget its dimensions, since that depends on the size of the
containing window, how it is packed or gridded, what is inside of the
frame, etc. None of that can be determined until the window is
actually mapped to the display.

Simply calling update will cause it to be displayed and thus give you
a reasonable number, though calling update is a relatively risky thing
to do.

On Wed, Apr 10, 2013 at 9:42 AM, GKalman <kalman_g at verizon.net> wrote:
>   Please look  at the  following Tkinter code fragment:
>
> #***
>  frm=Frame(root,bg="cyan")
>  frm.pack(side=TOP, fill=BOTH, expand=YES)
>  h= frm.winfo_height()
> print h, type(h)
> #***
>
> It returns  a value of h=1 and type= int
>
>   I remember seeing somewhere that the returned a value of h=1 means that it
> is RELATIVE wrt something.
> Question:  how can I get the ABSOLUTE value for height.
>
> BTW:
> h= frm.cget("height")
> print h
>
> results in a  value of h=0 !!!   why?
>
>
>
>
> --
> View this message in context: http://python.6.x6.nabble.com/question-on-winfo-height-tp5013753.html
> Sent from the Python - tkinter-discuss mailing list archive at Nabble.com.
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss


More information about the Tkinter-discuss mailing list