How to do this in GUI ?
1 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Joseph Cheng
2015-9-29
编辑:Joseph Cheng
2015-9-29
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 个评论
Joseph Cheng
2015-9-29
if it answered your question with no further inquiries please accept the answer so it gets marked as the one that worked.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!