Tkinter 用点画创建线条

Tkinter Create Line with Stipple

我发现可以在 Python tkinter 中制作点画线。 (见此处:Canvas Line Objects

它指出我需要一个位图文件并定义stipple=bitmap_file

我试过这个:

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

但是,控制台随后显示: _tkinter.TclError: error reading bitmap file "CheckedLine.bmp"

有人可以帮忙吗?

他们所说的“位图”的page linked to in the OP, also links to a detailed description,他们从来没有提到它是一个文件,而是一个位图。

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.

第 5.7 节有关要使用的文件的详细信息-:

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.


有关 .xbm 格式的更多信息 this 可能会有用。

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.


注意:

Incase,您使用上面列出的标准位图和在提供的 link 中,它们呈现为如下所示 -: