6
canvas.create_line(50, 500, 950, 500, dash=(5, 1), tags="splitDistance")

This will create a line which looks like this:

XXXXX XXXXX XXXXX XXXXX

5 dashes, 1 space and then repeat, as told by this documentation

But when changing the 1 to any value, it will not change the gap size.

dash=(5, 100):

XXXXX XXXXX XXXXX XXXXX

Another weird behavior is that the first parameter only changes the outcome when it is dividable by 5 for example: (5, 10, 15, 20...)

dash=(1, 1):

X X X X X X X X X X X X

dash=(4, 1):

X X X X X X X X X X X X

dash=(5, 1):

XXXXX XXXXX XXXXX XXXXX

Here is a image from the program and result:

image from the program and result

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Blightbuster
  • 481
  • 7
  • 16
  • `dash` works for me on Linux Mint. Maybe it depends on system. Or add in question minimal, working example with your problem - so we could run it and compare result. – furas Jan 22 '17 at 23:18
  • Ok I added a picture. Im using Windows 10. – Blightbuster Jan 22 '17 at 23:30
  • Just found a similar question which is 7 years old and has no answer. http://smtp.grokbase.com/t/python/tkinter-discuss/099vgnqzr0/python-3-1-canvas-rectangle-dash-dashoffset – Blightbuster Jan 22 '17 at 23:34
  • on Linux it looks like this: [canvas dash](https://github.com/furas/python-examples/tree/master/tkinter/canvas-dash). Seems problem is only on Windows - I can't help you. – furas Jan 22 '17 at 23:57
  • 1
    From [this](https://mail.python.org/pipermail/python-list/2001-October/070905.html) it sounds like it's system dependent thing. I get the same results as you one Windows 7 in both Python 2 & 3. Regardless, in the future please include the code in your question _as text_, not an image. – martineau Jan 23 '17 at 00:59
  • Please don't post code as an image. – Bryan Oakley Jan 23 '17 at 03:02

1 Answers1

7

Different platforms support different dash patterns. What you are seeing is the fact that Windows doesn't support the same dash patterns as X-based systems.

From the canonical tcl/tk documentation on the dash attribute comes these example (in tcl syntax, but the translation to tkinter is trivial):

-dash .     → -dash {2 4}
-dash -     → -dash {6 4}
-dash -.    → -dash {6 4 2 4}
-dash -..   → -dash {6 4 2 4 2 4}
-dash {. }  → -dash {2 8}
-dash ,     → -dash {4 4}

The documentation goes on to say this:

On systems which support only a limited set of dash patterns, the dash pattern will be displayed as the closest dash pattern that is available. For example, on Windows only the first 4 of the above examples are available. The last 2 examples will be displayed identically to the first one.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685