473,563 Members | 2,668 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_rectan gle(1, 1, 299, 299)
c.create_rectan gle(3, 3, 297, 297)
c.create_rectan gle(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 1621
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_rectan gle(1, 1, 299, 299)
c.create_rectan gle(3, 3, 297, 297)
c.create_rectan gle(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************ *************** **********@pyth on.org>,
"Fredrik Lundh" <fr*****@python ware.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
5960
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 filling the remainder of the window. Mind you, this is a contrived test application to help me understand Tkinter and Python, not an actual...
2
3996
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 extra step is necessary. This causes the "graph" function to execute when the button is created: Button(root, text='OK', command=graph(canvas))) ...
0
1082
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 rectangle and text objects that can be moved along with clicking and dragging the mouse. Everything works fine and well when I have just a few of these...
1
10475
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) does the FAQ list at python-dot-org. Any pointers would be very much appreciated. (In related news, I would also like to find out what's going on...
0
7664
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7583
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7885
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7638
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5484
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3642
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2082
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 we have to send another system
1
1198
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.