Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #73208

Re: Lines on a tkinter.Canvas

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'canvas': 0.07; 'tkinter': 0.07; '(self,': 0.09; '__init__': 0.09; 'canvas.': 0.09; 'pixel': 0.09; 'pixels': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:skip:t 10': 0.09; 'width': 0.09; 'def': 0.12; 'random': 0.14; '(0,': 0.16; '250)': 0.16; 'idea:': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'script,': 0.16; 'self.y': 0.16; 'subject:Lines': 0.16; 'url:py': 0.16; 'y):': 0.16; 'all.': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'differ': 0.19; 'import': 0.22; 'this?': 0.23; 'header:User-Agent:1': 0.23; 'specify': 0.24; '(or': 0.24; 'least': 0.26; 'header:X-Complaints-To:1': 0.27; 'tried': 0.27; 'point': 0.28; 'resolution': 0.29; "doesn't": 0.30; 'code': 0.31; 'lines': 0.31; 'that.': 0.31; 'dimensions': 0.31; 'horizontal': 0.31; 'pa,': 0.31; 'class': 0.32; 'another': 0.32; 'url:python': 0.33; 'level.': 0.33; 'skip:# 10': 0.33; 'could': 0.34; 'display': 0.35; 'board': 0.35; 'point.': 0.35; 'prepare': 0.35; 'but': 0.35; 'there': 0.35; 'height': 0.36; 'method': 0.36; 'should': 0.36; 'application': 0.37; 'too': 0.37; 'turn': 0.37; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'color': 0.61; 'show': 0.63; 'high': 0.63; 'here': 0.66; 'therefore': 0.72; 'blow': 0.84; 'draws': 0.84; 'everything.': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: Lines on a tkinter.Canvas
Date Thu, 12 Jun 2014 09:02:44 +0200
Organization None
References <1402538245.73470.YahooMailNeo@web140102.mail.bf1.yahoo.com>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p57bd9de5.dip0.t-ipconnect.de
User-Agent KNode/4.11.5
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.11031.1402556589.18130.python-list@python.org> (permalink)
Lines 67
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1402556589 news.xs4all.nl 2962 [2001:888:2000:d::a6]:50462
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:73208

Show key headers only | View raw


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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Lines on a tkinter.Canvas Peter Otten <__peter__@web.de> - 2014-06-12 09:02 +0200

csiph-web