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
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
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 it doesn't work by using pack()
function, you can try to add canvas.update()
after using canvas.pack()
.