# Simple way to add button to UI

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.

• Do you want to run your script right from the text editor with parameters from a panel or just the last operator settings? – stacker Jul 25 '14 at 14:42
• 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 – Val Jul 25 '14 at 14:51
• 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 – 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:

http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Cookbook/Panels_and_Operators/Ping_Pong

• the ping-pong example helped me. thx! – Val Jul 29 '14 at 11:54
• 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 ? – Prokop Hapala Oct 6 '16 at 8:40
• 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 – 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.