Displaying buttons
Intuitively, pushing a button performs a transformative action. Since buttons take up space, the default interface displays only the more generic operations. When we write custom interfaces, we can add more buttons based on our specific needs. This is made easier by how Blender translates operators into buttons. In this section, we’ll learn how buttons and operators are equivalent when it comes to the graphical interface.
Using the operator method
We can use the UILayout.operator
method to display a button. In Blender, a button executes an operator. This operator is found through its identifier – that is, the bl_idname
attribute, which we encountered in Chapter 3 – and every operator must have it.
For instance, to add a button that deletes the selected objects, we must provide the identifier of the Delete operator.
If we use the Delete action from the Object menu or the X key and look into the Scripting workspace, we will find this...