How to do this in GUI ?

1 visualización (últimos 30 días)
Bence Salanki
Bence Salanki el 29 de Sept. de 2015
Comentada: Joseph Cheng el 29 de Sept. de 2015
Hi,
I'm trying to get know with GUI. First I'd like to make 2 edit boxes and a pushbutton. The function of this stuff would be that when the user writes some data into the first edit box (can be characters and numeric values also) and hits the pushbutton, the written data should appear in the other edit box. I was wondering that I should write the code under the pushbutton's callback function ? I tried this:
function pushbutton_Callback(hObject, eventdata, handles)
s = get(handles.editbox1, 'String'); if((str2double(get(handles.pushbutton, 'String'))) == 1) set(handles.editbox2, 'String', s); end
What's the problem? Thanks.

Respuesta aceptada

Joseph Cheng
Joseph Cheng el 29 de Sept. de 2015
Editada: Joseph Cheng el 29 de Sept. de 2015
so the behavior of the pushbutton_callback() function is to run when the push button is pressed. so you are 99% there. get rid of the if statement and have the function be like
function pushbutton_Callback(hObject, eventdata, handles)
s = get(handles.editbox1, 'String');
set(handles.editbox2, 'String', s);
Since the callback will only run when the pushbutton is pressed there is no need to check the state of the button (unless you set the pushbutton to be a toggle button). if you do need to check the state of the button (ie as a togglebutton) you would use get(hangles.pushbutton,'value'). I'd read the documentation on pushbuttons/uicontrols to double check that last part.
  2 comentarios
Bence Salanki
Bence Salanki el 29 de Sept. de 2015
Thank you so much!
Joseph Cheng
Joseph Cheng el 29 de Sept. de 2015
if it answered your question with no further inquiries please accept the answer so it gets marked as the one that worked.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks 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