How do I get an event when I click on a text box in Blender?

Here is to get an idea.

I have not tried to follow the GUI design literally, only to show the example. :slight_smile:

Also the part for making the calculator work is another topic.
You would just use eval and have it work in a snap.
Python eval(): Evaluate Expressions Dynamically – Real Python

import bpy

class SimpleOperator(bpy.types.Operator):
    """Tooltip"""
    bl_idname = "scene.simple_operator"
    bl_label = "Simple Operator"
    bl_context = "scene"
    bl_options = {"INTERNAL"}
    option : bpy.props.StringProperty(name='option')
    buffer : bpy.props.StringProperty(name='result')
    
    def execute(self, context):
        print('option',self.option)
        
        if self.option == 'c':
            self.buffer = ''
        else:
            self.buffer += self.option
        
        print('buffer',self.buffer)
            
        return {'FINISHED'}

class LayoutDemoPanel(bpy.types.Panel):
    """Creates a Panel in the scene context of the properties editor"""
    bl_label = "Layout Demo"
    bl_idname = "SCENE_PT_layout"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "scene"

    def op(self, layout, value):
        layout.operator("scene.simple_operator", text=value).option=value

    def draw(self, context):
        layout = self.layout
        
        # to create three horizontal rows
        col = layout.column(align=True)
            
        # to create three vertical columns
        row = col.row(align=True)
        self.op(row, "1")
        self.op(row, "2")
        self.op(row, "3")
        # ...
        row = col.row(align=True)
        self.op(row, "4")
        self.op(row, "5")
        self.op(row, "6")
        # ...
        row = col.row(align=True)
        self.op(row, "7")
        self.op(row, "8")
        self.op(row, "9")                
        # ...
        row = col.row(align=True)
        self.op(row, "0")
                  
        # to create actions
        row = layout.row(align=True)
        self.op(row, "=")
        self.op(row, "+")
        self.op(row, "-")
        self.op(row, "*")
        self.op(row, "/")
        self.op(row, "c")
        
def register():
    bpy.utils.register_class(LayoutDemoPanel)
    bpy.utils.register_class(SimpleOperator)

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

if __name__ == "__main__":
    register()


1 Like