how to see the typed letter in GUI

1 visualización (últimos 30 días)
Pat
Pat el 22 de Abr. de 2014
Comentada: Walter Roberson el 22 de Abr. de 2014
I have acode below (in key press function) GUI
password = get(handles.edit1,'String');
key = get(handles.figure1,'currentkey');
key1=get(handles.figure1,'currentcharacter')
switch key
case 'backspace'
password = password(1:end-1); % Delete the last character in the password
otherwise
password = [password get(handles.figure1,'currentcharacter')] % Add the typed character to the password
end
SizePass = size(password) % Find the number of asterisks
if SizePass(2) > 0
asterisk(1,1:SizePass(2)) = '*'; % Create a string of asterisks the same size as the password
set(handles.edit1,'String',asterisk) % Set the text in the password edit box to the asterisk string
else
set(handles.edit1,'String','')
end
I have created a GUI with one edit boxThe above code is to mask the typed letter in edit box into asterisk,but i cannot see the typed password,then the variable password ,if i have typed 123 in edit box,the edit box show 3 asterisk but in that variable password it shows **3,y i get like this

Respuesta aceptada

Walter Roberson
Walter Roberson el 22 de Abr. de 2014
Reading or changing the String of an edit handle gives odd results in a key press function callback.
I think Yair has a way of getting it to work using Java.
You may wish to look in the File Exchange for password boxes.
  4 comentarios
Pat
Pat el 22 de Abr. de 2014
Actually walter i have seen all these and have taken code that only,it was a dialogue box that pops up for asking input,but i created edit box in gui and have made changed over tere..but have some problem in it
Walter Roberson
Walter Roberson el 22 de Abr. de 2014
You have your code set password to get() the String of the edit box, and you do that every time you go through the callback. You have been changing the edit box to display '*' as you go, so the next time through the callback it is those '*' that are going to be there to be pulled out by your get() of the 'String' property.
If you look at the contribution I linked to above, notice that they initialize password differently:
password = get(h,'Userdata');
That is, the real characters of the password are being stored in the UserData field as you go, and at the end when the user is ready go on, you would get() the UserData field for the completed password. Of course you need to store the characters into the UserData as you go; the contribution does that.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Search Path en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by