MATLAB Answers

How to make popup menu work with left mouse click in matlab GUI?

12 ビュー (過去 30 日間)
Hi
I am using the Matlab Guide tool for creation of GUI. I have created a pop-up menu in Guide tool and listed a 40 set of strings in the dropdown list in codes.
For eg:
A={'hi','bye'};set(handles.popupmenu_1,'string',string(A));
I have used the above code in the popupmenu_1 callback function. After I select the "hi" in the drop down list, the "bye" is displayed. I want to display all strings (hi & bye) once i made left mouse selection in the popup menu.
Even i have tried with "Buttondownfunction", there also i have a constraint that to prior selection of rightclick on the mouse button.
can someone suggest me how to do the left mouse selection displays all set of strings in the popmenu at very first time itself?
Pls let me know if need clarifications.

採用された回答

Image Analyst
Image Analyst 2021 年 8 月 18 日
Generally you'd list all 40 items to fill up the popup either in the String property of the popup in GUIDE, or you'd assign them and send them to the popup in your app's OpeningFcn() function. It's very strange to alter the popup contents in the callback itself, though it can be done.
You didn't say how you wanted the list of items to be "displayed". Do you want them in a string called txtPopup on the GUI?
handles.txtPopup.String = handles.popupmenu1.String;
Do you want to print them out to the command window?
popupStrings = handles.popupmenu1.String;
for k = 1 : numel(popupStrings)
fprintf('Item #%d is %s\n', k, popupStrings{k});
end
I don't believe you need to use Buttondownfunction at all.
  3 件のコメント
Gopinath Karuppannan
Gopinath Karuppannan 2021 年 8 月 19 日
Thanks , It works fine.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by