Python Forum

Full Version: Problem with the input
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone!

I'm making a script with allows my users to visualize what they are typing.
I need to ask them to write down their emails and I'm having a problem with visualizing the at sign: @

I tried
if ‘@’ in keys:
…email.text = email.text+ ‘@’
and
if ‘At’ in keys:
…email.text = email.text+ ‘@’
but it is not working...
not clear what you are having problem with

>>> user = 'marios'
>>> user + '@'
'marios@'
or better - using f-strings (string-formatting)

>>> email = f'{user}@python-forum.io'
>>> email
'[email protected]'
please post minimal reproducible example. If you get any traceback - post it in full, in error tags
Thanks a lot for your reply!

I have a code element which allows my users to type something on the keyboard and see what they are typing on the screen.

keys = event.getKeys()
if len(keys):
    if 'space' in keys:
        some.text = some.text + ' '
    elif 'backspace' in keys:
        some.text = some.text[:-1]
    elif 'lshift' in keys or 'rshift' in keys:
        modify = True
    else:
        if modify:
            some.text = some.text + keys[0].upper()
            modify = False
        else:
            some.text = some.text + keys[0]
I need to modify it so they can type and see on the screen their emails (and not just letters or numbers). I try adding those two lines in my code:

    elif 'at' in keys:
        age.text = age.text + '@'
But although I do not get any error message, if I try to type the @, it is not visualized on the screen. So I wonder how can I correctly code it?
Sorry, but really it's not clear what you are doing. is it GUI? Or webapp? Or something else? What is code element? What is event? What exactly see what they are typing on the screen should mean - i.e. normally when you take user input user can see what they type? Where do you display anything? What OS, what python version and so on and so on....
Please, provide minimal runable example that we can run and reproduce the problem
I'm working with Psychopy (https://www.psychopy.org/), it's a code element in PsychoPy
The example of this code element can be found here:
https://gitlab.pavlovia.org/demos/textinput