How to find out height of a Canvas
Robert Roy
rjroy at takingcontrol.com
Tue Jun 6 21:55:17 EDT 2000
On Sun, 4 Jun 2000 13:53 +0100 (BST), digitig at cix.co.uk (Tim Rowe)
wrote:
>In article <eaq_4.3871$JO2.84543 at news2-win.server.ntlworld.com>,
>richard_chamberlain at ntlworld.com (richard_chamberlain) wrote:
>
>> Hi Tim,
>>
>> from Tkinter import *
>> root=Tk()
>> canvas=Canvas(root,height=250,width=100)
>> canvas.pack()
>> print canvas ['height']
>>
>> canvas.itemcget has two arguments, the first is the tag or id of a
>> particular widget on the canvas and the second is the option you want
>> back.
You might want to look at the winfo_height method. Getting the height
configuration value is not always accurate.
import Tkinter
root=Tkinter.Tk()
root.geometry('400x200+40+40')
canvas=Tkinter.Canvas(root, height=100, background='green')
canvas.pack(fill='both', expand=1)
# canvas.winfo_height will return 1 when the window is first created
# the update command sets the geometry
root.update()
print canvas["height"]
print canvas.winfo_height()
root.mainloop()
Bob
>
>Thanks -- it looks as if I was making things much more complicated than
>they need to be. Situation normal!
More information about the Python-list
mailing list