Unusable outer edge of Tkinter canvases?

D

Dave Opstad

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):

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
 
F

Fredrik Lundh

Dave said:
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):


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>
 
D

Dave Opstad

"Fredrik Lundh said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top