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


Groups > comp.lang.python > #73241

Re: Lines on a tkinter.Canvas

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 <izecksohn@yahoo.com>
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 <mailman.11027.1402548495.18130.python-list@python.org> <bvthovFg8ldU1@mid.individual.net>
Date Thu, 12 Jun 2014 16:11:34 -0700 (PDT)
From Pedro Izecksohn <izecksohn@yahoo.com>
Subject Re: Lines on a tkinter.Canvas
To "python-list@python.org" <python-list@python.org>
In-Reply-To <bvthovFg8ldU1@mid.individual.net>
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 <izecksohn@yahoo.com>
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.11045.1402614834.18130.python-list@python.org> (permalink)
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

Show key headers only | View raw


----- Original Message -----

> From: Gregory Ewing
> To: python-list@python.org
> Cc: 
> Sent: Thursday, June 12, 2014 8:38 AM
> Subject: Re: Lines on a tkinter.Canvas
> 
> Pedro Izecksohn wrote:
>>  The Canvas' method create_line turns on at least 2 pixels. But I want 
> to turn
>>  on many single pixels on a Canvas.
> 
> You could try using a 1x1 rectangle instead.
> 
> However, be aware that either of these will use quite a
> lot of memory per pixel. If you are drawing a very large
> number of pixels, this could cause performance problems.
> In that case, you might want to use a different approach,
> such as creating an image and telling the canvas to display
> the image.

  Thank you Greg. Your second approach works and the script became:

#!/usr/bin/python3

import tkinter as tk

BITMAP = '''
#define im_width 1
#define im_height 1
static char im_bits[] = {
0xff
};
'''

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")
    self.objects_drawn = []
  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):
    bitmap = tk.BitmapImage (data=BITMAP, foreground = color)
    self.objects_drawn.append (bitmap)
    self.canvas.create_image (p.x, p.y, image = bitmap)

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()

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Lines on a tkinter.Canvas Pedro Izecksohn <izecksohn@yahoo.com> - 2014-06-11 18:57 -0700
  Re: Lines on a tkinter.Canvas Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-06-12 23:38 +1200
    Re: Lines on a tkinter.Canvas Terry Reedy <tjreedy@udel.edu> - 2014-06-12 13:44 -0400
    Re: Lines on a tkinter.Canvas Pedro Izecksohn <izecksohn@yahoo.com> - 2014-06-12 13:33 -0700
    Re: Lines on a tkinter.Canvas Pedro Izecksohn <izecksohn@yahoo.com> - 2014-06-12 16:11 -0700
      Re: Lines on a tkinter.Canvas Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-06-13 12:31 +1200

csiph-web