Sure, you can do that in code. Here's an example, though you'll likely need to season it to taste based on your code strucuture.
func _ready():
$TextureRect.connect("mouse_entered", self, "_on_mouse_entered")
$TextureRect.connect("mouse_exited", self, "_on_mouse_exited")
func _on_mouse_entered():
print("Mouse entered")
func _on_mouse_exited():
print("Mouse exited")
Here, I'm referencing a TextureRect
instance that I created in the editor, but it doesn't matter. Just replace my $TextureRect
with your code-created reference.