Skip to content

NodeCanvas

Akash Bora edited this page Jun 11, 2023 · 8 revisions

NodeCanvas

This is the parent widget where all nodes will be drawn.

Features

  • We can add our own grid image in the canvas. (Make sure the image size is big enough)

    Default grids are: ["lines", "dots", None]

  • It has drag and zoom ability, every canvas object is moved except the grid image.

  • It can save or load node trees.

canvas_types

Usage

root = tkinter.Tk()
canvas = NodeCanvas(root)
canvas.pack()
...

Arguments

Parameter Description
master parent widget to which the canvas will be attached
bg specify the bg color of canvas (it is not visible if grid_image have no transparency)
width width of the canvas
height height of the canvas
grid_image paste the grid image to the canvas, default grid name: "lines"
zoom enable/disable the zoom feature (boolean)
move enable/disable the drag feature (boolean)
wire_color change the line colors of attached nodes
wire_hover_color change the activefill color of the lines
wire_width change the width of the lines
wire_dash enable/disable dotted lines (boolean)

Methods

  • .configure(args...): change some attributes for the canvas like wire_colors, bg, grid_image etc.
  • .save(filename): save the node tree to a file. Eg: canvas.save("canvas.json")
  • .load(filename): load the node tree back to the canvas. Eg: canvas.load("canvas.json")
  • .clear(): delete all the nodes from the canvas
Clone this wiki locally