필터 지우기
필터 지우기

How to change text in a textbox from a pushbutton's callback?

조회 수: 3 (최근 30일)
Faith Huynh
Faith Huynh 2016년 6월 24일
댓글: rocketboyjka 2016년 6월 27일
I have a GUI that is supposed to create a folder of shortcuts in a certain file. I would like to be able to have a button called "change destination" that, in its callback, should bring up a file directory and allows the user to choose a destination for the shortcut folder, then updates a textbox to show the new destination path.
function [OUT] = action(IN)
switch(IN)
case 'change'
dest = uigetdir;
set(handles.destination,'String',dest);
end
end
When I run the above (action() is called in my GUI's callback for the pushbutton 'change'), I get an error saying that destination (the handle for my textbox) is an undefined variable.
Can anyone tell me what I'm doing wrong? Thank you!

답변 (1개)

rocketboyjka
rocketboyjka 2016년 6월 24일
1) Try passing 'handles' into the function:
action(IN,handles)
2) It is also good practice (I don't think your function requires it, but I usually do it so as not to forget.) to end the function with an update to the handles structure. Typically:
guidata(hObject,handles)
  댓글 수: 2
Faith Huynh
Faith Huynh 2016년 6월 27일
Hey there,
Awesome, thanks for the tip-- I've never worked with GUIs before, so this is all new. I added handles to the inputs, but I'm not sure where to go from there.
rocketboyjka
rocketboyjka 2016년 6월 27일
Is it still throwing an error? If so, can you post more than just the code snippet?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by