Tutorial 2 ‐ Print Hello World - Suzie1/ComfyUI_Guide_To_Making_Custom_Nodes GitHub Wiki
In this tutorial, we are going to build the Print Hello World node below
The node outputs a message to the ComfyUI console log.
Steps
1. Make a file called nodes.py in your nodes subfolder
2. Open the file in Notepad++ or an IDE
Windows Notepad is not recommended.
3. Setup the class structure
class PrintHelloWorld:
@classmethod
def INPUT_TYPES(cls):
RETURN_TYPES = ()
FUNCTION = "print_text"
OUTPUT_NODE = True
CATEGORY = "Tutorial Nodes"
def print_text(self, text):
return {}
RETURN_TYPES
defines the output types. In this there is an output to the console, but a output type is not required for this.FUNCTION
is used to specify the main functionOUTPUT_NODE
indicates this is the node that produces the ouput. A workflow must contain at least one output node to run. Usually this would beSave Image
orPreview Image
, but in this case there is no image output.CATEGORY
specifies where the node will be included in the ComfyUI node menu- The first parameter in the main function should always be
self
- The return statement is used to specify the objects that are passed to the node outputs. In this case there are none.
5. Add the input parameters into the class structure
- The input parameters must match the parameters in the
print_text
function
return {"required": {
"text": ("STRING", {"multiline": False, "default": "Hello World"}),
}
}
6. Add the main function into the class structure
- In this case the function consists of a formatted print statement.
- Python is fussy about indents. Take care to use precise indentation.
print(f"Tutorial Text : {text}")
7. Check the completed node
It should look like this:
class PrintHelloWorld:
@classmethod
def INPUT_TYPES(cls):
return {"required": {
"text": ("STRING", {"multiline": False, "default": "Hello World"}),
}
}
RETURN_TYPES = ()
FUNCTION = "print_text"
OUTPUT_NODE = True
CATEGORY = "Tutorial Nodes"
def print_text(self, text):
print(f"Tutorial Text : {text}")
return {}
__init__.py
file
Add the node to the __init__.py
file
1. Add a class mapping for the Hello World node in the "Hello World": HelloWorld,
__init__.py
file
2. Check the updated It should look like this:
from .nodes.nodes import *
NODE_CLASS_MAPPINGS = {
"Print Hello World": PrintHelloWorld,
}
print("\033[34mComfyUI Tutorial Nodes: \033[92mLoaded\033[0m")