AsiJapan
AsiJapan

Reputation: 313

Quit an App designer GUI using a code - Matlab

How can I quit an App designer GUI using a button?

I tried this and it does not work:

function QuitButtonPushed(app, event)
          fig = uifigure;
          selection = uiconfirm(fig,'Close software?','Quit', 'Icon','warning');  
          switch selection
          case 'Yes'
          app.delete;
          case 'No'
         return 
        end

Upvotes: 2

Views: 832

Answers (1)

Rotem
Rotem

Reputation: 32124

The switch case should be with 'OK' and 'Cancel' and not 'Yes', 'No'.

It is also recommended to pass app.UIFigure instead of using fig = uifigure;:

selection = uiconfirm(app.UIFigure,'Close software?','Quit', 'Icon','warning');

switch selection
    case 'OK'
        app.delete();
    case 'Cancel'
        return
end

Upvotes: 1

Related Questions