This is the most easy example.
#py3
from tkinter import *
tk = Tk()
canvas = Canvas(tk, width= 500 , height = 400)
canvas.winfo_height()
#In [4]: canvas.winfo_height()
#Out[4]: 1
In order to get the width and height of the tkinter window, we can use winfo_width () and winfo_height () helper methods that help to grab the current width and height of the tkinter window. Running the above code will display a window that contains a button.
Tkinter provides numerous of universal widget methods or basic widget methods which works almost with all the available widgets. winfo_ismapped () method – This method is used to check whether the specified widget is visible or not.
Tkinter provides numerous of universal widget methods or basic widget methods which works almost with all the available widgets. This method is used to check whether the specified widget is visible or not. Return Value: Returns True if widget is visible (or mapped), otherwise returns False.
winfo fpixels window number Returns a floating-point value giving the number of pixels in window corresponding to the distance given by number. Number may be specified in any of the forms acceptable to Tk_GetScreenMM, such as ``2.0c'' or ``1i''. The return value may be fractional; for an integer value, use winfo pixels.
You have to pack the canvas element in the window before getting it's height. The height return is the actual height.
>>> from tkinter import *
>>> tk = Tk()
>>> canvas = Canvas(tk, width= 500 , height = 400)
>>> canvas.winfo_height()
1
>>> canvas.pack()
>>> canvas.winfo_height()
402
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With