Hi @edwardstern242 welcome to the forum.
Suppose you have a string defined as follows:
my_string='hello world'
In general, you can retrieve what the user has typed into a text box, and compare it to my_string
as follows:
user_input=self.text_box_1.text #assumes your text_box is called "text_box_1"
if user_input==my_string:
print('the strings match!')
If you want to begin the comparison based on an event, have a look at the events for a the TextBox:
You can see that I’ve set up a function called text_box_1_pressed_enter
to run when enter has been pressed in the TextBox. In the code editor, I would have that function defined, and the comparisons that you want to make would be placed inside that function, like so:
def text_box_1_pressed_enter(self, **event_args):
"""This method is called when the user presses Enter in this text box"""
my_string='hello world'
user_input=self.text_box_1.text #or event_args['sender'].text
if user_input==my_string:
print('the strings match!')
If you want the comparison to happen every time the text has been changed, then you would associate a function to the “change” event rather than the “pressed enter” event.
Here is a clone to demonstrate all of the above:
https://anvil.works/build#clone:TAFNJMB45WPIWWU5=QBJY6PGZ5W7T6MLO7DWVU4AE
A couple other notes:
It is helpful to show the exact error you are getting when posting on the forum rather than simply “This doesn’t work”. This helps us all to debug more effectively. You can also format your code nicely on the forum by wrapping your code block with triple backticks. For example:
```python
print(‘nicely formatted code’)
```