How to do this in GUI ?

5 views (last 30 days)
Bence Salanki
Bence Salanki on 29 Sep 2015
Commented: Joseph Cheng on 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.

Accepted Answer

Joseph Cheng
Joseph Cheng on 29 Sep 2015
Edited: Joseph Cheng on 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 Comments
Bence Salanki
Bence Salanki on 29 Sep 2015
Thank you so much!
Joseph Cheng
Joseph Cheng on 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.

Sign in to comment.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!