How to do this in GUI ?

1 vue (au cours des 30 derniers jours)
Bence Salanki
Bence Salanki le 29 Sep 2015
Commenté : Joseph Cheng le 29 Sep 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.

Réponse acceptée

Joseph Cheng
Joseph Cheng le 29 Sep 2015
Modifié(e) : Joseph Cheng le 29 Sep 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 commentaires
Bence Salanki
Bence Salanki le 29 Sep 2015
Thank you so much!
Joseph Cheng
Joseph Cheng le 29 Sep 2015
if it answered your question with no further inquiries please accept the answer so it gets marked as the one that worked.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by