Hot to set fields from one GUI to another
古いコメントを表示
Dear all,
I've been able to transfer variables from one gui to another, there's plenty of stuff around on that.
What I haven't been able to do is to set a field of a GUI from another GUI.
Here's an example: I have two GUIs opened: GUI1 and GUI2. GUI1 has a text box, GUI2 has a push button. Now, when I push the button on GUI2 I would like so set the string in the text box of GUI1 to something.
How can I achieve this?
Thanks!
Lorenzo
採用された回答
その他の回答 (3 件)
If you can provide variables from one GUI to the other, you can provide the handles struct also. And there you find the handles of the GUI objects. If your GUIs have the tags "GUI1" and "GUI2" (a bad choice, by the way), you can set the text of an object in GUI1 from a callback of GUI2:
function ButtonCallback(hObject, EventData, handles)
% Better do this once only!
gui1H = findobj(allchild(0), 'flat', 'tag', 'GUI1'); % [EDITED]
gui1Handles = guidata(gui1H);
set(gui1Handles.Button1, 'String', 'hello')
Add a TRY/CATCH for a meaningful error message, if the 2nd GUI has been closed before.
4 件のコメント
In the code you have posted, the variable GUI1 seems to be undefined. Beside the typo, that in my code GUI2 and GUI1 have been confused, the FINDOBJ is used to find the handle of the other GUI. It would be better to obtain this handle e.g. when the other figure is created.
Lorenzo
2014 年 1 月 21 日
Lorenzo
2014 年 1 月 22 日
Lorenzo
2014 年 1 月 22 日
カテゴリ
ヘルプ センター および File Exchange で Creating, Deleting, and Querying Graphics Objects についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!