How to get button to change its texture every time it is pressed?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Cakee

I want it so then when the button is pressed, it will change from texture1 to texture2 and then when pressed again change back to texture1.
I can only get it so then when the button is held down instead of staying once the button has lifted.

:bust_in_silhouette: Reply From: sirAlexDev

In script load both of this texture then connect pressed signal to some_func then in some_func set texture_normal to what you want

:bust_in_silhouette: Reply From: deaton64
extends Node2D

var _texture1 = load("res://number1.png")
var _texture2 = load("res://number2.png")
var _texture_toggle: int = 1

func _on_TextureButton_pressed() -> void:
	if _texture_toggle == 1:
		$TextureButton.texture_pressed = _texture2
		$TextureButton.texture_normal = _texture1
		_texture_toggle = 2
		$TextureButton.texture_pressed = _texture1
		$TextureButton.texture_normal = _texture2
		_texture_toggle = 1