Opening a GUI from another GUI with a delay in App Designer

7 次查看(过去 30 天)
I have to open a second GUI2 from a main GUI1. I would like to open the GUI2 with a delay. I used the timer in this way: t = timer('TimerFcn', @(~,~) uiwait(app2.UIFigure), 'StartDelay', 5); start(t); and pause(5) but the second GUI is open immediatley. The istruction to open the GUI2 is uiwait(app2.UIFigure). In documentation about uiwait(app2.UIFigure) I have seen that I can use uiwait(app2.UIFigure, timeout) but also this method is not working.
I have to open the GUI2 in a loop. This is the code
for i=1:30
% do something
uiwait(app2.UIFigure)
% do something
I used also this:
time_await = 5; % Time await in seconds
t0 = tic;
% Start timer
while toc(t0) < time_await
drawnow;
end
No solution is working and I don't know how to open the second GUI with a delaly

回答(2 个)

Rik
Rik 2023-4-10
I suspect the new GUI is opened because Matlab is unable to store the anonymous function without creating that new GUI.
What you can do is write a wrapper function that opens the second GUI. That way you can use the timer to run that function with a delay and all should be well.

Amit Dhakite
Amit Dhakite 2023-4-10
编辑:Amit Dhakite 2023-4-10
Hi Tania,
As per my understanding, you would like to open a second GUI2 from main GUI1, with some x seconds delay.
You can use pause() function to delay the execution of the code. Here is an example code for opening a second GUI2 from GUI1 after a delay of 5 seconds:
% Button pushed function: Callback in which you want to open second GUI
function buttonPushed(app, event)
% Introduce a delay of 5 seconds
pause(5);
% Create an instance of the second GUI
secondGUI = GUI2;
% Show the second GUI
secondGUI.UIFigure.Visible = 'on';
end
Please note that you can customize the above code to meet your specific requirements.
For further information, kindly refer to the following links.
  1. pause(): https://www.mathworks.com/help/matlab/ref/pause.html
  2. UIFigure: https://www.mathworks.com/help/matlab/ref/uifigure.html

类别

Help CenterFile Exchange 中查找有关 Dialog Boxes 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by