Can I use code to set up the form instead of using the graphic interface?


I don't like setting up things by clicking and dragging. How can I use code to set up my scene?

  • Nathan Lovato replied

    You can set up the user interface with imperative code and generally about everything you do in the editor you can do in code in Godot.

    A little warning: it will be way less efficient to do everything with code for UI design. It makes iterating on the placement and look of things much slower, so I would recommend getting comfortable with working with the editor.

    That said, here's an example of how you could set up three UI nodes with code: a Label in a VBoxContainer in a PanelContainer. It's also important to know how to do that for the cases where you need to create new UI nodes at runtime.

    var panel_container = PanelContainer.new()
    # This is equivalent of using the Layout menu in the editor toolbar
    var vbox_container = VBoxContainer.new()
    var label = Label.new()
    label.text = "Hello World!"

    You create the nodes and add them as children of one another, like how you would do in the editor.

    1 love