adding custom menu object to create menu?

can someone help me understand why I can’t get my window object to be created when I click on it in the create menu?

I currently get the warning “you are trying to create a MonoBehaviour using the ‘new’ keyword This is not allowed.”
but when make my window not inherit monobehaviour it doesn’t do anything.

this is my current code…

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tizen;
using UnityEditor;

public class Menu : MonoBehaviour {
   
    [MenuItem ("GameObject/UI/Window")]
    private static void CreateWindowObject()
    {
        Window window = new Window();
    }
} 

public class Window : MonoBehaviour {

    public GUISkin skin = null;
    public Rect rect = new Rect(15, 15, 250, 250);

    private void OnGUI()
    {
        GUI.skin = skin;
        rect = GUI.Window(0, rect, OnWindow, "MyWindow");
    }

    private void OnWindow(int id)
    {
       
    }
}

Are you creating a custom editor window? If so, it should extend EditorWindow, not MonoBehaviour (along with a few other steps).

no its a ui window not an editor window

In that case, your window inherits MonoBehaviour, making it a component. Components can’t live by themselves, they need to be attached to a GameObject.

GameObject obj = new GameObject(); // If you want each window to be its own GameObject
Window window = obj.AddComponent<Window>();

You can also not inherit MonoBehaviour, and call its OnGUI method from an active component.