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?

 采纳的回答

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

3 个评论

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

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by