GUI data Update

1 次查看(过去 30 天)
Gerd
Gerd 2011-3-8
Hi guys,
I'm building a gui in matlab and have a question about the guidata update. I want to let the user change a value on a "Edit Text" control and this value changes the current plot function. I wait until the 'return' key is pressed and process the data. The problem is that the user has to hit the return key twice to change the value. I think the guidata is not updated. Does anyone has an advice? Gerd
function txt_Faktor_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to txt_Faktor (see GCBO)
% eventdata structure with the following fields (see UICONTROL)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)
if strcmp(eventdata.Key,'return')
handles.Faktor = str2double(get(handles.txt_Faktor,'String'));
% store variable
guidata(hObject,handles);
plotMainWindow(hObject, eventdata, handles);
end

采纳的回答

Walter Roberson
Walter Roberson 2011-3-8
Why are you doing things that way instead of just using a callback function on the edit uicontrol ?
Note by the way, that you should be taking precautions in case the user entered something other than a number.
  3 个评论
Walter Roberson
Walter Roberson 2011-3-8
If you set
uicontrol('Style','edit', 'Callback', @txt_Faktor_Fcn)
then the callback will only be activated if "whenever you activate the uicontrol object (e.g., when you click on a push button or move a slider)" In the case of an edit callback, that occurs when you press return on the control, and does NOT occur if you type into the control but then click outside of the control.
Gerd
Gerd 2011-3-8
Thank you Walter,
the GUI works now fine. Thank you for the explanation.
Gerd

请先登录,再进行评论。

更多回答(0 个)

类别

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