Borrar filtros
Borrar filtros

Return values from uifigure by pressing OK button

26 visualizaciones (últimos 30 días)
Julia Fischer
Julia Fischer el 14 de Jul. de 2022
Editada: Jonas el 14 de Jul. de 2022
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;
...

Respuesta aceptada

Jonas
Jonas el 14 de Jul. de 2022
Editada: Jonas el 14 de Jul. de 2022
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

Más respuestas (0)

Categorías

Más información sobre Develop uifigure-Based Apps en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by