Specifications

Selecting GUI Options
3-31
function pushbutton1_Callback(hObject, eventdata, handles)
Assigning a Callback Property String
When you first add a component to your GUI layout, its Callback property is
set to the string
%automatic. This string signals GUIDE to replace it with one
that calls the appropriate callback subfunction in the GUI M-file when you
save or run the GUI. For example, GUIDE sets the
Callback property for
pushbutton1 uicontrol to
my_gui('pushbutton1_Callback',gcbo,[],guidata(gcbo))
where
my_gui is the name of the GUI M-file.
pushbutton1 is the value of the component’s Tag property.
pushbutton1_Callback is the name of the callback routine subfunction
defined in
my_gui.
gcbo is a command that returns the handle of the callback object (i.e.,
pushbutton1).
[] is a place holder for the currently unused eventdata argument.
guidata(gcbo) returns the handles structure.
See “Callback Function Syntax” on page 3-30 for more information on callback
function arguments and “Changing Tag and Callback Properties” on page 3-53
for more information on how to change the names used by GUIDE.
Adding Callbacks to the M-file
If you want GUIDE to include other callbacks in the GUI M-file and provide
names for them, you can do one of the following:
In the Property Inspector, set the value of the callback property, e.g.,
KeyPressFcn, to the string %automatic. GUIDE adds the callback to the
M-file the next time you save the GUI.
In the
View menu, select View Callbacks. Then select the desired callback,
e.g.,
KeyPressFcn. GUIDE adds the callback to the M-file, opens the M-file
if it is not already open, and scrolls to the first line of the new callback.