Unusable outer edge of Tkinter canvases?

Discussion in 'Python' started by Dave Opstad, May 25, 2005.

  1. Dave Opstad

    Dave Opstad Guest

    When drawing rectangles in Tkinter canvases I've noticed the outer edges
    (say 3-5 pixels) don't always draw. For instance, try typing this in an
    interactive session (Terminal in OS X or Command Prompt in Windows XP):

    >>> import Tkinter as T
    >>> root = T.Tk()
    >>> f = T.Frame(root)
    >>> f.grid()
    >>> c = T.Canvas(f, width = 300, height = 300)
    >>> c.grid()
    >>> c.create_rectangle(1, 1, 299, 299)
    >>> c.create_rectangle(3, 3, 297, 297)
    >>> c.create_rectangle(5, 5, 295, 295)


    On the Mac, the first two rectangles only partly show up (two sides for
    the first one and three for the second), while the third one draws
    completely. On Windows the first rectangle appears partially and the
    final two appear completely.

    Is there some simple setting I'm missing? I've tried gridding the canvas
    with padx, pady and also ipadx, ipady values but nothing seems to help
    make the whole rectangle (1, 1, 299, 299) appear.

    I'm using Python 2.4.1 and TclTkAqua 8.4.9 on Mac OS X 10.3.7, and
    Python 2.3.4 on Windows XP (which comes with a Tcl/Tk whose version I
    don't know).

    Thanks for any insights,
    Dave
    Dave Opstad, May 25, 2005
    #1
    1. Advertising

  2. Dave Opstad wrote:

    > When drawing rectangles in Tkinter canvases I've noticed the outer edges
    > (say 3-5 pixels) don't always draw. For instance, try typing this in an
    > interactive session (Terminal in OS X or Command Prompt in Windows XP):
    >
    > >>> import Tkinter as T
    > >>> root = T.Tk()
    > >>> f = T.Frame(root)
    > >>> f.grid()
    > >>> c = T.Canvas(f, width = 300, height = 300)
    > >>> c.grid()
    > >>> c.create_rectangle(1, 1, 299, 299)
    > >>> c.create_rectangle(3, 3, 297, 297)
    > >>> c.create_rectangle(5, 5, 295, 295)

    >
    > On the Mac, the first two rectangles only partly show up (two sides for
    > the first one and three for the second), while the third one draws
    > completely. On Windows the first rectangle appears partially and the
    > final two appear completely.
    >
    > Is there some simple setting I'm missing? I've tried gridding the canvas
    > with padx, pady and also ipadx, ipady values but nothing seems to help
    > make the whole rectangle (1, 1, 299, 299) appear.


    by default, the coordinate system is aligned with the widget's upper
    left corner, which means that things you draw will be covered by the
    inner border.

    to fix this, you can either set the border width to zero, add scrollbars
    to the widget (this fixes the coordinate system), or explicitly reset the
    coordinate system:

    w.xview_moveto(0)
    w.yview_moveto(0)

    </F>
    Fredrik Lundh, May 25, 2005
    #2
    1. Advertising

  3. Dave Opstad

    Dave Opstad Guest

    In article <>,
    "Fredrik Lundh" <> wrote:

    > to fix this, you can either set the border width to zero, add scrollbars
    > to the widget (this fixes the coordinate system), or explicitly reset the
    > coordinate system:
    >
    > w.xview_moveto(0)
    > w.yview_moveto(0)


    The canvas's border width was already zero, but when I moved the origin
    to (0,0) via xview_moveto and yview_moveto I was able to successfully
    draw all three rectangles.

    Just out of curiosity, why aren't these zeroed to start with when the
    widget is created, given the default border width is zero? And is there
    a way of determining what they're set at, something like a xview_get()
    method? I looked at all the canvas's attributes (calling configure())
    but nothing in there referred to xview or yview.

    Thanks for the help!
    Dave
    Dave Opstad, May 25, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    524
    Steven Cheng[MSFT]
    Sep 19, 2005
  2. =?ISO-8859-1?Q?Mickel_Gr=F6nroos?=

    Memory and speed with lots of objects on Tkinter.Canvases

    =?ISO-8859-1?Q?Mickel_Gr=F6nroos?=, Jan 19, 2004, in forum: Python
    Replies:
    0
    Views:
    341
    =?ISO-8859-1?Q?Mickel_Gr=F6nroos?=
    Jan 19, 2004
  3. Sean McIlroy

    reusing Tkinter Canvases

    Sean McIlroy, Jan 14, 2005, in forum: Python
    Replies:
    1
    Views:
    327
    Cameron Laird
    Jan 15, 2005
  4. Ferdi Smit
    Replies:
    0
    Views:
    774
    Ferdi Smit
    Oct 10, 2005
  5. denish
    Replies:
    5
    Views:
    5,615
Loading...

Share This Page