Let's say the textfield is called element1 and it's on the widget called text gui. You would simply assign the variable to the text gui element once the button or action is clicked or performed.
So it would look like this:
$my variable = widget["textgui"].element["0001"].text