我想在我的弹出菜单中添加元素,用户将其写入文本字段,我是matlab的新手,所以任何解释都非常感激,我知道它是关于回调的按钮,但我不知道该怎么做......
我的gui到目前为止:
到目前为止我的代码:
function varargout = popupmenu(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @popupmenu_OpeningFcn, ...
'gui_OutputFcn', @popupmenu_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
function popupmenu_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = popupmenu_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function edit1_Callback(hObject, eventdata, handles)
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function popupmenu1_Callback(hObject, eventdata, handles)
function popupmenu1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function pushbutton1_Callback(hObject, eventdata, handles)
答案 0 :(得分:0)
在pushbutton1_Callback
您可以添加:
new_item=get(handles.edit_1,'string') % to get the string from the edit box
tmp=get(handles.popupmenu1,'string') % to get the actual list of items in the popup menu
tmp{end+1}=new_item % to add the string
set(handles.popupmenu1,'string',tmp) % to update the popup menu items