How to find out height of a Canvas

Frank Niessink frankn=nuws at cs.vu.nl
Sun Jun 4 11:44:37 EDT 2000


Tim Rowe <digitig at cix.co.uk> wrote:
> How do I find out the height of a Tkinter Canvas? canvas.itemcget looks 
> promising, but it needs two arguments (I get a Tcl error if I omit the 
> second argument, or set it to None), and I can't find any documentation on 
> what the second argument should be (or the first argument, for that 
> matter; I'm assuming /that/ should be a string containing the name of the 
> attribute).

Canvas.itemcget gets the options of an item on the canvas, not of the
canvas itself. Use Canvas.config for that, e.g.:

>>> from Tkinter import *
>>> root = Tk()
>>> c = Canvas(root)
>>> c.pack()
>>> c.config('height')
('height', 'height', 'Height', '7c', '250')

The second argument of itemcget is the option you want to know about, e.g.:
>>> tag = c.create_line(0, 0, 100, 100, arrow='both')
>>> c.itemcget(tag, 'arrow')
'both'

Cheers, Frank
-- 
There is a theory which states that if ever anyone discovers exactly what the
Universe is for and why it is here, it will instantly disappear and be
replaced by something even more bizarre and inexplicable. There is another 
theory which states that this has already happened.
	-- Douglas Adams, 'The Restaurant at the End of the Universe'



More information about the Python-list mailing list