Reputation: 433
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
Upvotes: 15
Views: 15889
Reputation: 553
If it doesn't work by using pack()
function,
you can try to add canvas.update()
after using canvas.pack()
.
Upvotes: 15
Reputation: 31339
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
Upvotes: 12