Effacer les filtres
Effacer les filtres

How to get parent name of a child GUI component?

11 vues (au cours des 30 derniers jours)
Khanh
Khanh le 20 Oct 2014
Commenté : Khanh le 21 Oct 2014
Hi everybody,
I have a figure with 'Name' property: 'My figure' and 'Tag' property: 'figure1'.
In this figure, I have a push button with 'Name' property: 'Push me' and 'Tag' property: 'pushbutton1'
How can I get the push button's parent name in a programmatic GUI?
Is its parent name 'Myfigure' or 'figure1'?
% Code generated by FIG2M made by Thomas Montagnon (The MathWorks France)
% Great thanks to him
% --- FIGURE -------------------------------------
handles.figure1 = figure( ...
'Tag', 'figure1', ...
'Units', 'characters', ...
'Position', [102.8 24.3076923076923 114 32.9230769230769], ...
'Name', 'figure1', ...
'MenuBar', 'none', ...
'NumberTitle', 'off', ...
'Color', [0.941 0.941 0.941]);
% --- PUSHBUTTONS -------------------------------------
handles.pushbutton6 = uicontrol( ...
'Parent', handles.figure1, ...
'Tag', 'pushbutton6', ...
'Style', 'pushbutton', ...
'Units', 'characters', ...
'Position', [13.4 22.9230769230769 24.4 1.92307692307692], ...
'String', 'Push Button');
a=get(handles.pushbutton6,'parent') % a is a double, I don't know how to get parent name from it.

Réponse acceptée

Orion
Orion le 20 Oct 2014
Hi,
Actually, more than a double, a is a handle. (try ishandle(a))
In your case, with
a=get(handles.pushbutton6,'parent')
a is the handle of the parent of handles.pushbutton6, which here is the figure.
And to get the name of this (which usually is different of the tag) :
get(a,'Name')
ans =
figure1
  1 commentaire
Khanh
Khanh le 21 Oct 2014
Great. Thank you so much.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by