GUI Event and Callback Assistance

조회 수: 6 (최근 30일)
Aaron Chen
Aaron Chen 2021년 6월 3일
Introduction:
As a moderately skilled coder, I have recently revisited GUIs, and a recent project consists of a simple GUI for turning on a light. Now, I have created GUIs in the past, but they did not feature events, making this project my first GUI to ever feature events in the Callback function.
function Light_Switch();
figure = uifigure('Name', 'Test', 'Units', 'Pixels', 'Resize', 'On', ...
'Scrollable', 'On', 'WindowState', 'Maximized', 'Color', 'Black');
light = uilamp(figure, 'Color', 'Yellow', 'Enable', 'Off', ...
'Position', [600, 420, 300, 90]);
figure.KeyPressFcn = {@Luminance_settings, light}
end
function Luminance_settings(figure, Control, light); % Control is the event variable
switch Control.Key % Events are controlled/determined by keyboard inputs
case 'Spacebar'
light.Enable = 'On';
figure.Color = 'White';
end
end
Program Purpose Explanation:
The main function Light_Switch contains the figure with a UI Lamp object. When the spacebar is pressed, the callback function Luminance_settings is supposed to activate the lamp object via the event variable Control.
Problem
Unfortunately, my coding knowledge does not extend to GUI Callback Events, and I was unable to find sufficient information/documentation of the Mathworks website explaining events involving keyboard input. When executed, the function displays the GUI with the lamp object, but does not respond when the spacebar is pressed. I am unable to determine whether I used the wrong variables, or if the event codes were entirely incorrect.
Due to my course requirements, I am unable to used nested Callback functions for any project involving GUIs. Therefore, my project features separate function and callback function.
If anyone is able to provide assistance, please feel free to do so.
Additional Requests:
If anyone happens to know, can anyone provide some available callback event documentation? Can anyone please provide a detailed explanation about callback events? And can anyone please provide some more keyboard input variables for callback events?

답변 (0개)

카테고리

Help CenterFile Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by