Don't allow spaces in the textbox

I have a textbox and a button, what I want to happen is when the user just enters spaces on the textbox then clicked on the button, it won’t do anything.

How can I do this?

Thanks!

text = event.source.parent.getComponent('Text Field').text 
spaces = " "
if spaces in text:
	print "dont do anything"
else:
	print "go ahead"

The above script will flag any text that has one or more spaces, including when the user enters multiple words like ‘hello world’.

If you want to prevent the user from entering just whitespace (or an empty text box), try text = event.source.parent.getComponent('Text Field').text if not text or text.isspace(): print "dont do anything" else: print "go ahead"

‘not text’ checks for an empty textbox; text.isspace() checks for just whitespace.

hth,

Nice! Thanks! :thumb_left: