Make Pushbutton Visible in GUI
7 ビュー (過去 30 日間)
古いコメントを表示
I'm attempting to make a pushbutton visible in my GUI when a specific selection is picked in the popup menu. Here's my code:
hbutton0 = uicontrol('Style','pushbutton','String','Load Time','Position',...
[150,365,90,30],'Callback',@callbackfn);
set(hbutton0,'Visible','Off')
hspopup0 = uicontrol('Style','popup','BackgroundColor','white','position',[20,350,100,40],'String',{'Modality';'PBS';'DS'});
if strcmp(get(hspopup0,'String'),'PBS')
set(hbutton0,'Visible','On');
end
Yet the hbutton0 does not appear when 'PBS' is selected. Can you please help? Thank you.
0 件のコメント
回答 (2 件)
Walter Roberson
2015 年 10 月 11 日
The String property of a uicontrol('Style','popup') always holds all of the menu items, not just the currently selected item. In order to determine the currently selected item, you need to look at the numeric property Value of the uicontrol (which can be empty if nothing has been selected.) You can get() the String property and index it by the Value property if you want to know the string that was selected.
0 件のコメント
Image Analyst
2015 年 10 月 11 日
% Get the index of the item they chose.
selectedIndex = get(hspopup0, 'Value');
% Get a list of everything in the popup.
allItems = get(hspopup0,'String'); % Cell array of all items in the popup
% Get the string indicating the exact one item that they chose.
selectedItem = allItems{selectedIndex};
% Now do the comparison.
if strcmp(selectedItem ,'PBS')
set(hbutton0,'Visible','On');
end
4 件のコメント
Walter Roberson
2015 年 10 月 11 日
Works for me when I test it by using your code
hbutton0 = uicontrol('Style','pushbutton','String','Load Time','Position',...
[150,365,90,30],'Callback',@callbackfn);
set(hbutton0,'Visible','Off')
hspopup0 = uicontrol('Style','popup','BackgroundColor','white','position',[20,350,100,40],'String',{'Modality';'PBS';'DS'});
and then selecting the PBS entry and then using Image Analyst's code.
If you are looking to have it immediately switch then you would need to set up a callback on hspopup0
Image Analyst
2015 年 10 月 11 日
Use the debugger to step through your code and find out what lines of code it's actually executing.
参考
カテゴリ
Help Center および File Exchange で Entering Commands についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!