Push Button help!
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Divija Aleti
il 21 Apr 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 Commenti
Vedere anche
Categorie
Scopri di più su Startup and Shutdown in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!