Blank GUI figure handle? (noob question)
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
sorry for this noob question, i just started to learn about GUI making, but i cannot figure out this:
when i create a new blank GUI using GUIDE, an .m file is generated. i cannot find inside this .m file the handle of the blank figure. callback functions of all gui elements (e.g. push buttons) are pointing to the same handles "hObject".
so what is the handle of the blank figure, and what are the handles of added gui elements?
0 comentarios
Respuesta aceptada
Jan
el 27 de Ag. de 2013
Editada: Jan
el 27 de Ag. de 2013
Although it might look confusing, the situation is clear and surely will become clear to you soon. You can create a button programatically or by guide. Both are equivalent, when you write:
handles.myButton1 = uicontrol('Style', 'PushButton', 'Tag', 'myButton1', ...
'Callback', @myButton1Callback);
Now the callback of the button is called as:
function myButton1Callback(hObject, EventData)
And inside this function you can obtain the current version of the handles struct easily:
handles = guidata(hObject);
GUIDE appends the handles struct as 3rd input automatically already, such that you get:
function myButton1Callback(hObject, EventData, handles)
But I'm not sure, if this handles struct is the newest version already (I'm not working with GUIDE), but the guidata method shown above will work also.
Each object in a GUI has its own handles, which can be seen as a pointer or address of the GUI object. In all callbacks, the handle of the activated object is called "hObject", but you can modify the name of the variable freely:
function myButton1Callback(ButtonHandle, EventData)
set(ButtonHandle, 'String', 'I am pressed');
0 comentarios
Más respuestas (3)
Vishal Rane
el 27 de Ag. de 2013
The hObject is the handle to the object/component triggering the callback. Also the gui/figure handle would be probably in handles.figure. The handles structure contains handles of all the gui components and the gui itself.
Image Analyst
el 27 de Ag. de 2013
In GUIDE, double click on the figure to bring up the property inspector. Look at the "Tag" property - that is the handle name of the figure. For example, if the tag is figMainWindow, then in your code you use handles.figMainWindow whenever you need to refer to the main window (GUI) that contains all of your other controls (listboxes, radio buttons, etc.). If you add a push button with the tag "Go", then you will refer to handles.Go.
Ver también
Categorías
Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!