0

I found the possibility to make a stippled line in Python tkinter. (Seen here: Canvas Line Objects)

It states that I need a bitmap file and define stipple=bitmap_file

I tried this in:

# Import the required libraries
from tkinter import *

# Create an instance of tkinter frame or window
win=Tk()

# Set the size of the tkinter window
win.geometry("700x350")

# Create a canvas widget
canvas=Canvas(win, width=500, height=300)
canvas.pack()

# Add a line in canvas widget
canvas.create_line(100,200,200,35, stipple='@CheckedLine.bmp', fill='red', width=5)

win.mainloop()

However, the console then says: _tkinter.TclError: error reading bitmap file "CheckedLine.bmp"

Can someone help?

Soda
  • 89
  • 1
  • 8

1 Answers1

1

The page linked to in the OP, also links to a detailed description of what they meant by a "bitmap", they never mention it to be a file but rather a bitmap.

stipple

To draw a stippled line, set this option to a bitmap that specifies the stippling pattern, such as stipple='gray25'. See Section 5.7, “Bitmaps” for the possible values.

Section 5.7 details about the files to be used -:

The graphic above shows Button widgets bearing the standard bitmaps. From left to right, they are 'error', 'gray75', 'gray50', 'gray25', 'gray12', 'hourglass', 'info', 'questhead', 'question', and 'warning'.

You can use your own bitmaps. Any file in .xbm (X bit map) format will work. In place of a standard bitmap name, use the string '@' followed by the pathname of the .xbm file.


For more information on the .xbm format this may be useful.

Some image viewers/converters, e.g., XnView, FFmpeg and IrfanView, support XBM. A 48×48 XBM can be converted to Ikon and eventually X-Face with Netpbm tools.

ImageMagick supports converting images both to and from XBM. GIMP may be used to create or modify images using the XBM format, and also supports converting images to and from the XBM format.


NOTE:

Incase, you use the standard bitmaps as listed above and in the link provided, they render to look like this -:

STANDARD BITMAPS

typedecker
  • 1,351
  • 2
  • 13
  • 25
  • I converted the .bmp to .xbm via GIMP. But the same error message occurs. – Soda Feb 28 '22 at 08:03
  • @Soda did you change the filename in your code? – typedecker Feb 28 '22 at 08:04
  • Change the extension of the file to .xbm in the code as well. – typedecker Feb 28 '22 at 08:18
  • Yes of course. ```canvas.create_line(100,200,200,35, stipple='@CheckedLine.xbm', fill='darkred', width=5)``` – Soda Feb 28 '22 at 08:26
  • can you provide a link to that xbm file of somewhere from where i can download it, it might help me test out a few things i think might work out – typedecker Feb 28 '22 at 08:26
  • You can download the file here: https://www.mediafire.com/file/npdztbktcxeioyv/CheckedLine.xbm/file – Soda Feb 28 '22 at 09:41
  • @Soda it might be related with the size of your stipple texture as well, like the size in pixels.. I found [one post](https://stackoverflow.com/questions/11176638/tkinter-tclerror-error-reading-bitmap-file) which might help fixing the file, as the code seems to be exactly as intended. – typedecker Feb 28 '22 at 14:38