How I make a pushbutton visible using another pushbutton in a GUI?

"Pushbutton 1" shows and work with graphical data essential to the "pushbutton 2" subprogram task. Pushing "pushbutton 2" before "pushbutton 1" leads to error. I want to make "pushbutton 2" inaccesible in the GUI until user press "pushbutton 1". How can I do it?

 Risposta accettata

You can use the properties 'enable' or 'visible'
set(handles.pushbutton1,'enable','off')
%or
set(handles.pushbutton1,'visible','off')

3 Commenti

In property inspector I set pushbutton 2 as "off", and then I have this code:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
set(handles.pushbutton2, 'enable','on')
The button shows grayed out, but pushing "pushbutton 1" doesn't make any change on "pushbutton 2". Am I missing something?
Set a breakpoint there and see if it actually executes that line. You can also use the 'visible' property to hide it or show it. Enable property enables or disables (grays out) the button. You might also try adding a drawnow after the set() call though it should not be necessary.
Don't forget to save your m-file

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Interactive Control and Callbacks in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by