How big is that canvas in the window?

Robert Roy rjroy at takingcontrol.com
Mon Aug 27 15:42:27 CEST 2001


On 26 Aug 2001 05:12:52 -0700, koen at behindthesofa.dhs.org (Koen
Bossers) wrote:

>Joseph Andrew Knapka <jknapka at earthlink.net> wrote in message news:<3B86C522.169F2868 at earthlink.net>...
>> Bob Greschke wrote:
>> > 
>> > Here's the idea:
>> > 
>> > www.passcal.nmt.edu/~bob/unlinked/images/trdpy.jpg
>> > 
>> > It's in Python/Tkinter.  See the "Plot" button?  I want to draw a
>> > graph in the black area.  How do I find out the dimensions of the
>> > black canvas area???  I can make a guess when I first draw everything
>> > by setting the size of everything, but I don't want to do that.  I
>> > want the user to be able to resize the window and then redraw the
>> > graph.  I got to exactly this same point in GTK+ and had to give up.
>> > Am I going to have to write this program in Java?? :-)
>> > 
>> > (The program is actually being written for/on a UNIX box.  I just had
>> > to use a Windows machine to get the screen dump.)
>> > 
>> > Thanks!
>> >
>
>interactive session:
>
>>>> from Tkinter import *
>>>> root = Tk()
>>>> canv = Canvas(root)
>>>> canv.pack()
>>>> canv.cget('height')
>'267'
>>>> canv.cget('width')
>'381'
>
>
>found at:
>http://www.pythonware.com/library/tkinter/introduction/index.htm.
>Section "Basic Widget Methods"
>
>Please bookmark this site: a lifesaver when programming with Tkinter.
>
>
>Cheers, Koen

Bob,

See also winfo_width, winfo_height. In some circumstances, I have
found these to be more reliable than cget('width"), and cget("height")


http://www.pythonware.com/library/tkinter/introduction/x9170-window-related-information.htm

also you might want to try using PMW 

http://pmw.sourceforge.net/

It has nice megawidgets including a scrolled canval



Bob Roy



More information about the Python-list mailing list