Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #73208 > unrolled thread
| Started by | Peter Otten <__peter__@web.de> |
|---|---|
| First post | 2014-06-12 09:02 +0200 |
| Last post | 2014-06-12 09:02 +0200 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Lines on a tkinter.Canvas Peter Otten <__peter__@web.de> - 2014-06-12 09:02 +0200
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2014-06-12 09:02 +0200 |
| Subject | Re: Lines on a tkinter.Canvas |
| Message-ID | <mailman.11031.1402556589.18130.python-list@python.org> |
Pedro Izecksohn wrote:
> The code available from:
> http://izecksohn.com/pedro/python/canvas/testing.py
> draws 2 horizontal lines on a Canvas. Why the 2 lines differ on thickness
> and length?
>
> The Canvas' method create_line turns on at least 2 pixels. But I want to
> turn on many single pixels on a Canvas. How should I do this? Canvas has
> no method create_pixel or create_point.
> #!/usr/bin/python3
>
> import tkinter as tk
>
> class Point ():
> def __init__ (self, x, y):
> self.x = x
> self.y = y
>
> class Board (tk.Frame):
> def __init__ (self, bg, dimensions):
> tk.Frame.__init__ (self, tk.Tk())
> self.pack()
> self.canvas = tk.Canvas (self, bd = 0, bg = bg, width = dimensions.x,
height = dimensions.y)
> self.canvas.pack (side = "top")
> def drawLine (self, pa, pb, color):
> self.canvas.create_line (pa.x, pa.y, pb.x, pb.y, fill = color)
> def drawPoint (self, p, color):
> self.canvas.create_line (p.x, p.y, p.x, p.y, fill = color)
>
> dimensions = Point (500, 500)
> board = Board ('black', dimensions)
> color = 'red'
> p = Point (0, 250)
> while (p.x < dimensions.x):
> board.drawPoint (p, color)
> p.x += 1
> pa = Point (0, 350)
> pb = Point (499, 350)
> board.drawLine (pa, pb, color)
> board.mainloop()
I just tried your script, and over here the line drawn with
> def drawLine (self, pa, pb, color):
> self.canvas.create_line (pa.x, pa.y, pb.x, pb.y, fill = color)
has a width of 1 pixel and does not include the end point. Therefore the
"line" drawn with
> def drawPoint (self, p, color):
> self.canvas.create_line (p.x, p.y, p.x, p.y, fill = color)
does not show up at all. You could try to specify the line width explicitly:
def drawPoint (self, p, color):
self.canvas.create_line (p.x, p.y, p.x+1, p.y, fill=color, width=1)
If that doesn't work (or there's too much overhead) use pillow to prepare an
image and show that.
Another random idea: if you have a high resolution display your OS might
blow up everything. In that case there would be no fix on the application
level.
Back to top | Article view | comp.lang.python
csiph-web