I'm looking for the simplest way to add a button and a text input field to Blender's UI so I can use some parameters in my Python script.

I've tried a few tutorials but...

This one uses the word self which throws me an error (name 'self' is not defined) http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Cookbook/Code_snippets/Interface#Using_scene_properties_to_store_information

In this one I cannot really see where the actual code to add to UI is http://www.blender.org/documentation/blender_python_api_2_57_release/bpy.types.Operator.html

Plus a few others that I don't understand at all.

  • $\begingroup$ Do you want to run your script right from the text editor with parameters from a panel or just the last operator settings? $\endgroup$ – stacker Jul 25 '14 at 14:42
  • $\begingroup$ what do you mean by 'last operator settings'? i guess, running from text editor is OK for me. i might think about improving it later on $\endgroup$ – Val Jul 25 '14 at 14:51
  • $\begingroup$ Last operator is the panel that is displayed in the 3D Tools panel after you invoked an operator e.g. Add/Mesh/Torus there you can setup the parameters for the last created object. If you need something like that see the example twisted.py wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Cookbook/… It still works with Blender 2.7 $\endgroup$ – stacker Jul 25 '14 at 16:28

You basically need to combine two of the Templates in Text Editor that ship with Blender:

An Operator and a panel. In the panel's draw() method, you add an operator to the layout, which will be represented by a clickable button. Clicking it will run the operator's execute() method.

Here is an example how interface and actions play together:


  • $\begingroup$ the ping-pong example helped me. thx! $\endgroup$ – Val Jul 29 '14 at 11:54
  • $\begingroup$ how to use the Ping_Pong example ? Should I run it in script editor (I tried, I don't see any result) or try to install it as addon (It seems it does not install) ? ... maybe I just cannot find where it should appear ? $\endgroup$ – Prokop Hapala Oct 6 '16 at 8:40
  • 1
    $\begingroup$ aha I found it ... it is in Properties panel on Object tab ... as described here bl_space_type = "PROPERTIES" and bl_context = "object" after running it from script editor $\endgroup$ – Prokop Hapala Oct 6 '16 at 8:44

I'm not quite sure how to have a string/integer inputbox, but this hopefully should help you with some of your creations:


Good luck my friend.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.