473,499 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unusable outer edge of Tkinter canvases?

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
Jul 19 '05 #1
2 1615
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>

Jul 19 '05 #2
In article <ma*************************************@python.or g>,
"Fredrik Lundh" <fr*****@pythonware.com> 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
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5956
by: Josh | last post by:
Caution, newbie approaching... I'm trying to come up with a very simple Tkinter test application that consists of a window with a drop-down menu bar at the top and a grid of colored rectangles...
2
3991
by: mksql | last post by:
New to Tkinter. Initially, I had some code that was executing button commands at creation, rather than waiting for user action. Some research here gave me a solution, but I am not sure why the...
0
1077
by: Mickel Grönroos | last post by:
Hi everybody, This is a question about Tkinter.Canvases and performance: I am writing a Tkinter application that among other things contains a number of Tkinter.Canvases that in turn hold...
1
10423
by: Elaine Jackson | last post by:
Newbie. Playing with the 'turtle' module and wondering if there's a way to save the graphics you make with it. The documentation itself has nothing to say about this, nor (as far as I can tell)...
0
7014
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7395
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4921
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3108
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.