Hi everyone!

I am starting with Godot. I want to create a simple interface. As a first test I want the game to create a Button and when I click on the Button, I want a WindowDialog to open. My problem is that the window is created but doesn't show up. Here's what I did:

First, I created a Control node as the Root of the game. I named it "RootNode".

Then I created a WindowDialog, with a Label Child. I named it "WindowTest" and I made it a class. WindowTest.gd:

extends WindowDialog

class_name WindowTest

func _ready():
	rect_min_size = Vector2(400,150)
	$Label.text = "This is a Test"
	
func _init():
	print("Window initialized")

Then I created a Button. Its name is "ButtonTest" and I made it a class too. When you click on it, a WindowTest should pop up. ButtonTest.gd :

extends Button

class_name ButtonTest

func _ready():
	rect_min_size = Vector2(150,75)
	text = "Click Me!"

func _init():
	print("Button initialized")

func _pressed():
	print("Touché")
	var wTest = WindowTest.new()
	wTest.popup()

Finally, I created a script, "Manager.gd" that is autoloaded. For now its task is to create a ButtonTest. Manager.gd:

extends Node

onready var RootNode = get_node("/root/RootNode/")

func _ready():
	print("Start")
	RootNode.add_child(ButtonTest.new())

So, when I run the RootNode scene, the ButtonTest is created and displayed. The debugger prints

Start
Button initialized

Then, I click on the button, and no window is shown, while the debugger prints

Touché
Window initialized

Thanks in advance for your help.

Try:

func _ready():
    rect_min_size = Vector2(150,75)
    text = "Click Me!"

func _init():
    print("Button initialized")

func _pressed():
    print("Touché")
    var wTest = WindowTest.new()
    add_child(wTest)
    wTest.popup()

Though I'm not sure how well it will work when you add your window as a child of the button. Might want that script to be added to another parent node and connect the button nodes signals to it.

edit: or you could try get_tree().get_current_scene().add_child(wTest) instead so it's added as child of root/current scene.

Of course! I need to add it as a child of an existing node! I put it as a child of the root node Manager.RootNode.add_child(wTest) Thank you.

2 years later