Return values from uifigure by pressing OK button
30 次查看(过去 30 天)
显示 更早的评论
Hello
I have a simple form composed of 2 uitextarea and an OK button
How can I tell the form to return the values of the text areas (whatever is inside ) to the workspae or a client function and closing the form after that , more or less like an inputdialog. I am not using the input dialog because I do have two buttons that fill the text areas. A short version follows:
Thanks!!
Julia
function myOutput=test()
mainFig=uifigure;
mainFig.Visible='off';
txt_pos=[30 210 100 40];
txtFile=uitextarea(mainFig,'Position',txt_pos);
txtFile.Editable='on';
txt_pos=[30 150 100 40];
txtCnf=uitextarea(mainFig,'Position',txt_pos);
txtCnf.Editable='on';
btn_pos=[300 50 100 40];
btnOk=uibutton(mainFig,...
'push',...
'Position',btn_pos,...
'ButtonPushedFcn',@(btnOk, event) pushBtOk(btnOk,mainFig,txtCnf,txtFile));
mainFig.Visible='on';
function pushBtOk(btn,mainfig,txtCnf,txtFile)
disp( txtCnf.Value);
disp( txtFile.Value);
%%put Values into myOutput
%%close(uifigure)
end
end
the client code
...
myOutput=test;
...
0 个评论
采纳的回答
Jonas
2022-7-14
编辑:Jonas
2022-7-14
if you nest functions in functions, you can directly use the defined variables. note also the uiwait to wait for the functio nreturn until the window was closed
function myOutput=test()
mainFig=uifigure;
mainFig.Visible='off';
txt_pos=[30 210 100 40];
txtFile=uitextarea(mainFig,'Position',txt_pos);
txtFile.Editable='on';
txt_pos=[30 150 100 40];
txtCnf=uitextarea(mainFig,'Position',txt_pos);
txtCnf.Editable='on';
btn_pos=[300 50 100 40];
btnOk=uibutton(mainFig,...
'push',...
'Position',btn_pos,...
'ButtonPushedFcn',@(~, ~) pushBtOk(txtCnf,txtFile));
mainFig.Visible='on';
uiwait(mainFig);
function pushBtOk(txtCnf,txtFile)
disp( txtCnf.Value);
disp( txtFile.Value);
myOutput(1)=txtCnf.Value;
myOutput(2)=txtFile.Value;
%%put Values into myOutput
close(mainFig)
end
end
try it using
twoFields=test();
you could even call the function without further arguments
'ButtonPushedFcn',@(~, ~) pushBtOk());
and
function pushBtOk()
%....
end
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Develop uifigure-Based Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!