Unusable outer edge of Tkinter canvases?

Fredrik Lundh fredrik at pythonware.com
Wed May 25 12:14:08 EDT 2005


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>






More information about the Python-list mailing list