Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!newsreader4.netcologne.de!news.netcologne.de!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'static': 0.04; 'canvas': 0.07; 'tkinter': 0.07; '#define': 0.09; '(self,': 0.09; '__init__': 0.09; 'canvas.': 0.09; 'pixels': 0.09; 'subject:skip:t 10': 0.09; 'width': 0.09; 'def': 0.12; "'''": 0.16; '(0,': 0.16; '250)': 0.16; 'received:66.196': 0.16; 'self.y': 0.16; 'subject:Lines': 0.16; 'y):': 0.16; 'thursday,': 0.16; 'wrote:': 0.18; 'drawing': 0.19; 'memory': 0.22; 'import': 0.22; 'to:name :python-list@python.org': 0.22; 'creating': 0.23; 'char': 0.24; 'instead.': 0.24; 'script': 0.25; 'second': 0.26; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'lines': 0.31; 'dimensions': 0.31; 'pa,': 0.31; 'class': 0.32; 'quite': 0.32; '-----': 0.33; 'skip:# 10': 0.33; 'could': 0.34; 'received:66': 0.35; 'display': 0.35; 'board': 0.35; 'case,': 0.35; 'but': 0.35; 'height': 0.36; 'method': 0.36; 'turn': 0.37; 'email addr:python.org': 0.37; 'performance': 0.37; 'thank': 0.38; 'to:addr:python-list': 0.38; 'subject:': 0.39; '12,': 0.39; '\xa0\xa0\xa0': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'problems.': 0.60; 'received:bf1.yahoo.com': 0.60; 'received:mail.bf1.yahoo.com': 0.60; 'color': 0.61; 're:': 0.63; 'such': 0.63; 'telling': 0.64; 'different': 0.65; 'email name :python-list': 0.65; 'header:Reply-To:1': 0.67; 'received:98.139.212': 0.68; 'received:bullet.mail.bf1.yahoo.com': 0.74; 'bitmap': 0.84; 'received:98.139.213': 0.91 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 360876.10103.bm@omp1027.mail.bf1.yahoo.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1402614694; bh=k7ELXwc/OOLN68//2cv/DGe5/hb4Yj0HNIr7fbn8res=; h=References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=I6clppHdwL9T+dXOV0uLFIWw6vqJR/2n8i0CkZSj1p2JOOZmJbwMMTi5Jl2DYrPbzJls79TnGLdBmnaK7Yga/GCE/+pRsxUzC4KfsD7GOgbI6PMhVCLCLrBExqnRYgcm+2Rj5Oh8yEWBt3fLICcwFoahL52BBRDLHjdl2lGZ2Rk= X-YMail-OSG: gB5QHxAVM1nJXRpowGeTuqwx0FuMg5wMMB6kWV9TgEVK5SX 0xpMKwzSXwqGO_xR6FLqgeQc9T8D2CN6lDTx.jaQaFg3C1KeQKvrQj0TgVAd YdmftmHiFvK0BR8Zx9yyzKXD4gUEWz597v_7TpUHJ_Q1oaBvUWxBwi.PJxU9 dVSlGAElSdtZk_aNXlGaIltgn2A65kd6KO3kjUuD6F_WG2IsQUSwCbSCoOrw 0KN7DoQtu.Q752yOwAh7ptPMUXH90pbCY5Q5T7asISDRt8A1gsebQBvt3d72 uDfYlsMg9a_TbDoIksvaObwA7N_tVNMhDRsxQOPKuMf0dSIHWE0iq10wDPdE MC.giVqM9X_d_kxj.Vb9ht1ffQtrM0sX.z8rzWtV94umqfZVf4ovDSPKz7TA Z7MgJisE8BAGSerrsABYzJ4WqmxhE2AXrV4TVRFoxQU9gpUHtjDJB33b5Tcr LGZpcDT9ROk0.zG8n0zqb7xXWtIsEGfHCQB5yNnT_kHRSsXsdApGzakqNzwP E4Axu97qK0SkBvJs2jKtl0zEbO0kwbQh0rOgDptcI9LfZGeORi1TlErTSQoT lH4E2XN280aFeNfnq4zxQilWrsAKG X-Rocket-MIMEInfo: 002.001, LS0tLS0gT3JpZ2luYWwgTWVzc2FnZSAtLS0tLQoKPiBGcm9tOiBHcmVnb3J5IEV3aW5nCj4gVG86IHB5dGhvbi1saXN0QHB5dGhvbi5vcmcKPiBDYzogCj4gU2VudDogVGh1cnNkYXksIEp1bmUgMTIsIDIwMTQgODozOCBBTQo.IFN1YmplY3Q6IFJlOiBMaW5lcyBvbiBhIHRraW50ZXIuQ2FudmFzCj4gCj4gUGVkcm8gSXplY2tzb2huIHdyb3RlOgo.PiAgVGhlIENhbnZhcycgbWV0aG9kIGNyZWF0ZV9saW5lIHR1cm5zIG9uIGF0IGxlYXN0IDIgcGl4ZWxzLiBCdXQgSSB3YW50IAo.IHRvIHR1cm4KPj4gIG9uIG0BMAEBAQE- X-Mailer: YahooMailWebService/0.8.190.668 References: Date: Thu, 12 Jun 2014 16:11:34 -0700 (PDT) From: Pedro Izecksohn Subject: Re: Lines on a tkinter.Canvas To: "python-list@python.org" In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Pedro Izecksohn List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1402614834 news.xs4all.nl 2883 [2001:888:2000:d::a6]:51374 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:73241 ----- Original Message -----=0A=0A> From: Gregory Ewing=0A> To: python-list= @python.org=0A> Cc: =0A> Sent: Thursday, June 12, 2014 8:38 AM=0A> Subject:= Re: Lines on a tkinter.Canvas=0A> =0A> Pedro Izecksohn wrote:=0A>> The Ca= nvas' method create_line turns on at least 2 pixels. But I want =0A> to tur= n=0A>> on many single pixels on a Canvas.=0A> =0A> You could try using a 1= x1 rectangle instead.=0A> =0A> However, be aware that either of these will = use quite a=0A> lot of memory per pixel. If you are drawing a very large=0A= > number of pixels, this could cause performance problems.=0A> In that case= , you might want to use a different approach,=0A> such as creating an image= and telling the canvas to display=0A> the image.=0A=0A=A0 Thank you Greg. = Your second approach works and the script became:=0A=0A#!/usr/bin/python3= =0A=0Aimport tkinter as tk=0A=0ABITMAP =3D '''=0A#define im_width 1=0A#defi= ne im_height 1=0Astatic char im_bits[] =3D {=0A0xff=0A};=0A'''=0A=0Aclass P= oint ():=0A=A0 def __init__ (self, x, y):=0A=A0=A0=A0 self.x =3D x=0A=A0=A0= =A0 self.y =3D y=0A=0Aclass Board (tk.Frame):=0A=A0 def __init__ (self, bg,= dimensions):=0A=A0=A0=A0 tk.Frame.__init__ (self, tk.Tk())=0A=A0=A0=A0 sel= f.pack()=0A=A0=A0=A0 self.canvas =3D tk.Canvas (self, bd =3D 0, bg =3D bg, = width =3D dimensions.x, height =3D dimensions.y)=0A=A0=A0=A0 self.canvas.pa= ck (side =3D "top")=0A=A0=A0=A0 self.objects_drawn =3D []=0A=A0 def drawLin= e (self, pa, pb, color):=0A=A0=A0=A0 self.canvas.create_line (pa.x, pa.y, p= b.x, pb.y, fill =3D color)=0A=A0 def drawPoint (self, p, color):=0A=A0=A0= =A0 bitmap =3D tk.BitmapImage (data=3DBITMAP, foreground =3D color)=0A=A0= =A0=A0 self.objects_drawn.append (bitmap)=0A=A0=A0=A0 self.canvas.create_im= age (p.x, p.y, image =3D bitmap)=0A=0Adimensions =3D Point (500, 500)=0Aboa= rd =3D Board ('black', dimensions)=0Acolor =3D 'red'=0Ap =3D Point (0, 250)= =0Awhile (p.x < dimensions.x):=0A=A0 board.drawPoint (p, color)=0A=A0 p.x += =3D 1=0Apa =3D Point (0, 350)=0Apb =3D Point (499, 350)=0Aboard.drawLine (p= a, pb, color)=0Aboard.mainloop()