set a blank window in GUI

조회 수: 15 (최근 30일)
ludvikjahn
ludvikjahn 2015년 3월 16일
답변: Omega 2024년 11월 19일 7:18
good Morning, I have a question: I created a program in gui with various edit texts, pushbuttons, static texts, popup menus,listboxes, etc.
When I try to select items for the second time, either the first ones remain written in the boxes(static texts, f.e.) or they remain highlighted, or the values remain in the "memory"..
I just want to "reset" all the properties at the end of the program, so that I can run a new one without the ancient value saved...
Is there a way to do it?

답변 (1개)

Omega
Omega 2024년 11월 19일 7:18
To reset a GUI in MATLAB and clear all previous values from edit texts, static texts, popup menus, listboxes, and other components, you can create a function that sets each component back to its default state. This function can be called at the end of your program or when you want to reset the GUI for a new run.
Here's a general approach to resetting various components in your GUI:
Step-by-Step Guide to Reset GUI Components
  1. Identify the GUI Components: Determine all the components that need to be reset. These typically include edit text, static text, popup menus, listboxes, etc.
  2. Create a Reset Function: Define a function in your GUI code that resets each component to its default state.
  3. Call the Reset Function: Invoke this function at the appropriate point in your program, such as at the end of execution or when a "Reset" button is pressed.
Example Code
Here's a simple example of how you might implement such a reset function:
function resetGUI(handles)
% Reset edit texts
set(handles.editText1, 'String', '');
set(handles.editText2, 'String', '');
% Reset static texts
set(handles.staticText1, 'String', 'Default Static Text');
% Reset popup menus to the first item
set(handles.popupMenu1, 'Value', 1);
% Reset listboxes to no selection
set(handles.listbox1, 'Value', []);
% Reset any other components as necessary
% ...
end
How to Use the Reset Function
  • At the End of Execution: Call resetGUI(handles) at the end of your main callback function to ensure the GUI is reset after execution.
  • With a Reset Button: Add a new pushbutton to your GUI labeled "Reset" and set its callback to call the resetGUI function.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by