How to set the value of a string property when a button is pressed? (Not in bge)
A button is a representation of an Operator in a layout. Example operator code:

import bpy

class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "object.simple_operator"
    bl_label = "Simple Object Operator"

    def execute(self, context):
        ob = context.object
        if ob is not None:
            ob.name = "Foo Bar"
        return {'FINISHED'}

def register():
    bpy.utils.register_class(SimpleOperator)

def unregister():
    bpy.utils.unregister_class(SimpleOperator)


if __name__ == "__main__":


You put your code to assign the new string value in the execute() method.

If you don't need any logic, but want to plainly assign to a context member, you may use the existing operators bpy.ops.wm.context_set_*:

import bpy

def draw_func(self, context):
    props = self.layout.operator("wm.context_set_string", text="Change object name")
    props.data_path = "object.name"
    props.value = "New Name"

bpy.types.OBJECT_PT_context_object.append(draw_func)


This code adds a button to the Object panel in the Properties Editor to change the context object's name property (which is a string).