I would just like to know if it would be possible to efficiently loop GUI functions.
function Menu1_CreateFcn(hObject, ~, ~) % --- Executes during object creation, after setting all properties.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white'); % Set the background color to white
end
function Menu2_CreateFcn(hObject, ~, ~) % --- Executes during object creation, after setting all properties.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white'); % Set the background color to white
end
function Menu3_CreateFcn(hObject, ~, ~) % --- Executes during object creation, after setting all properties.
% if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white'); % Set the background color to white
end
function Menu4_CreateFcn(hObject, ~, ~) % --- Executes during object creation, after setting all properties.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white'); % Set the background color to white
end
At the moment I have:
HandleNames = {'Menu1','Menu2','Menu3','Menu4'};
for d = 1:4
eval('function (HandleNames{d})_Callback(~, ~, ~)');
eval('function (HandleNames{d})_CreateFcn(hObject, ~, ~)');
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white'); % Set the background color to white
end
end
But I am well aware that the eval function is not good practice and it is throwing some errors in the command window but is still functioning like before. Would there be a more elegant way to do this or is it just a thing that I have to deal with, Cheers.