[Tkinter-discuss] Python 3.1; canvas rectangle dash & dashoffset

Lion Kimbro lionkimbro at gmail.com
Mon Sep 28 00:38:18 CEST 2009

  Dear tkinter peoples,

  I'm having difficulties with dash, and dashoffset;
  Can anyone identify what I'm doing wrong?

- Code: ----------------------------------------------------

import tkinter

def move_dashes(canvas, rect, offset):
    print("move_dashes(%s, %s, %s)" % (canvas, rect, offset))
    canvas.itemconfigure(rect, dashoffset=offset)
    canvas.after(1000, move_dashes, canvas, rect, offset+1)

def dashoffset_test():
    # Create a canvas
    canvas = tkinter.Canvas()
    # Put a comparison rectangle on the canvas.
    canvas.create_rectangle(7, 2, 27,28, outline="blue", dash=(5,1))
    # Put a rectangle on the canvas with a moving dash pattern.
    rect = canvas.create_rectangle(10,5, 30,30, dash=(4,1))
    canvas.after(1000, move_dashes, canvas, rect, 1)



  Two questions:

  1.  Why are the dash patterns so wildly different?

 canvas.create_rectangle(7, 2, 27,28, outline="blue", dash=(5,1))
 canvas.create_rectangle(10,5, 30,30, dash=(4,1))

  The first looks like:

xxxxxxxxxxxxxxx  xxxxxxxxxxxxxxx  xxxxxxxxxxxxxxx

  The second looks like:

xxx  xxx  xxx  xxx  xxx  xxx  xxx  xxx  xxx  xxx

  ...and yet, it's just (5,1) vs. (4,1)

  This is not what I expect from:

  2.  Why doesn't the dash pattern move?

  The call to canvas.itemconfigure(rect, dashoffset=offset)
  looks correct; Am I doing it wrong?

  I am using Python 3.1

  Thank you,
    Lion Kimbro
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tkinter-discuss/attachments/20090927/22f922bc/attachment.htm>

More information about the Tkinter-discuss mailing list