Python Forum
Problem with the input - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Problem with the input (/thread-26480.html)



Problem with the input - marios - May-03-2020

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...


RE: Problem with the input - buran - May-03-2020

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


RE: Problem with the input - marios - May-03-2020

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?


RE: Problem with the input - buran - May-03-2020

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


RE: Problem with the input - marios - May-03-2020

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