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

I want the GUI Numpad to appear as shown in this image when I click on the text box with the mouse.


To do this, I need to get the event when the text box is clicked in Blender, but I don’t know how to do that.
Google.
“blender python get click textbox event”.
and
“blender python if text input mode”.
but I couldn’t find any information about it.

How can I get the event when a textbox is clicked on in Blender?
I would like to get an event when a text box is clicked, not a text box like the name of an object, but a text box like the size of an object, where only numbers can be entered.

Translated with www.DeepL.com/Translator (free version)

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.
https://realpython.com/python-eval-function/

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

Thank you.

I was able to get Numpad to show up on my screen using free software in Windows.
The free software doesn’t have all the features I’m looking for, but I’m still lacking in Python skills, so I’m going to stop making my own software and use the free software now.

When I decide to make it myself again in a while, I will refer to what you have taught me.

Thank you very much for your help.

Translated with www.DeepL.com/Translator (free version)

1 Like