Info

此问题已关闭。 请重新打开它进行编辑或回答。

Writing callback for gui

2 次查看(过去 30 天)
vedesh Mohit
vedesh Mohit 2020-1-3
关闭: MATLAB Answer Bot 2021-8-20
hey,
I have to create a GUI that allows the user to construct a logic circuit from a menu using NOT, AND and OR gates. The gates are required to be placed in a static position in the construction window. How do I go about writing a callback for the pushbutton that when the user clicks the button, a popup menu appears to ask the user which section to place the gate?

回答(2 个)

Walter Roberson
Walter Roberson 2020-1-3
valid_sections = {'A3', 'B17', 'Thorax', 'Trailing L2 point'};
choice = menu('Choose a section to place into', valid_sections);
if choice == 0
user did not select anything
else
section_name = valid_sections{choice};
now do something based upon section_name
end
  1 个评论
Walter Roberson
Walter Roberson 2020-1-3
You can improve the above by something like,
if ~isfield(handles, 'used_sections')
handles.used_sections = {};
end
valid_sections = {'A3', 'B17', 'Thorax', 'Trailing L2 point'};
available_sections = setdiff(valid_sections, handles.used_sections);
choice = menu('Choose a section to place into', available_sections);
if choice == 0
user did not select anything
else
section_name = valid_sections{choice};
now do something based upon section_name
%update list of used sections
handles.used_sections{end+1} = section_name;
guidata(hObject, handles);
end

Image Analyst
Image Analyst 2020-1-3
Are you using GUIDE or App Designer? Either way, the source code will have a callback for the pushbutton. If using GUIDE, right click on the button and say "view callback", then, in the callback function, you can use either questdlg() or menu() to get the user's choice of NOT, AND, or OR.

Community Treasure Hunt

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

Start Hunting!

Translated by