Clear Filters
Clear Filters

How do I create a button that switches to another tab of a GUI?

24 views (last 30 days)
Here is my current code:
fig = uifigure('Name', 'Diabetes Diagnosis');
tabGroup = uitabgroup(fig);
sympTab = uitab(tabGroup,'Title','Symptoms');
famHistTab = uitab(tabGroup,'Title', 'Family History');
nextCtrl = uicontrol(sympTab, 'ButtonPushedFcn', {@buttonPushed,tabGroup,famHistTab});
function buttonPushed(uiTabGroup, uiFamHistTab)
uiTabGroup.SelectedTab = uiFamHistTab
end
The control is meant to switch from sympTab to famHistTab. I think the biggest problem is that I don't have any idea how to format a callback function. It outputs a figure, but the button doesn't have any apparent effect.

Answers (1)

Sreelakshmi S.B
Sreelakshmi S.B on 8 Mar 2019
You can try the code below. I’ve used uibutton in place of uicontrol since there is no 'ButtonPushedFcn' property on the UIControl class.
As for callback, assign a function handle that references the callback function to the ButtonDownFcn property of the button and mention the arguments you're passing when doing this,as shown below:
fig = uifigure('Name', 'Diabetes Diagnosis');
tabGroup = uitabgroup(fig);
sympTab = uitab(tabGroup,'Title','Symptoms');
famHistTab = uitab(tabGroup,'Title', 'Family History');
btn = uibutton(sympTab,'ButtonPushedFcn', @(arg1,arg2) buttonPushed(tabGroup,famHistTab));
% Create the function for the ButtonPushedFcn callback
function buttonPushed(uitabGroup,uiFamHistTab)
uitabGroup.SelectedTab = uiFamHistTab;
end

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!