Push Button help!
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello, I am trying to make two push buttons in MATLAB in which one allows me to quit the program and the other allows me to continue running it.
This is what I have as my function:
function ButtonQuit
message = sprintf("Are you sure you would like to quit gesture recognition?");
figquit = uifigure('Position', [450 150 395 175]);
tarea = uitextarea(figquit);
tarea.Value = message;
%movegui('southeast')
%uialert(figquit,message,'Warning','Icon','warning');
% Create a push button %left bottom width height
btn1 = uibutton(figquit,'push',...
'Position',[50, 20, 150, 50],...
'ButtonPushedFcn', @(btn,event) Button1(btn1));
btn1.Text = 'Yes, Quit';
btn2 = uibutton(figquit,'push',...
'Position',[250, 20, 150, 50],...
'ButtonPushedFcn', @(btn,event) Button2(btn2));
btn2.Text = 'No';
if Button1(btn1) %if btn1, confirm quit
return;
elseif Button2(btn2) %if btn2, close window, continue gesture recognition
close(fig);
end
end
I'm not sure if something is missing or I have the wrong idea entirely.
0 comentarios
Respuestas (1)
Divija Aleti
el 21 de Abr. de 2021
Hi Priyana,
There is a slight change in syntax that you need to make for the ButtonPushedFcn.
Assuming that when Button 1 is pushed, nothing should happen, and when Button 2 is pushed, the figure should close, I corrected the syntax as follows :
function ButtonQuit
message = sprintf("Are you sure you would like to quit gesture recognition?");
figquit = uifigure('Position', [450 150 395 175]);
tarea = uitextarea(figquit);
tarea.Value = message;
%movegui('southeast')
%uialert(figquit,message,'Warning','Icon','warning');
% Create a push button %left bottom width height
btn1 = uibutton(figquit,'push',...
'Position',[25, 20, 150, 50],...
'ButtonPushedFcn', @(btn,event) Button1);
btn1.Text = 'Yes, Quit';
btn2 = uibutton(figquit,'push',...
'Position',[225, 20, 150, 50],...
'ButtonPushedFcn', @(btn,event) Button2);
btn2.Text = 'No'
function Button1(btn, event)
return;
end
function Button2(btn, event)
close(figquit);
end
end
If you need an example on how to create a quit button, have a look at the following link:
Hope this helps !
Regards,
Divija
0 comentarios
Ver también
Categorías
Más información sobre Startup and Shutdown en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!