From: Matt Fig on
There is a subtle error in the gui example above. It was brought to my attention by someone who found this old thread and tried to implement the code. Since this might happen again, I am updating the code. I only hope that future readers read all the way to the last post!





function [] = mygui()
% If user types ACUF in the editbox, the popupmenu disappears.
S.KEY = []; % This will store the contents of editbox.
S.fh = figure('units','pixels',...
'position',[300 300 300 110],...
'menubar','none',...
'name','my_gui',...
'numbertitle','off',...
'resize','off');
S.pp = uicontrol('style','pop',...
'units','pixels',...
'position',[20 10 260 40],...
'string',{'ACUF','MAH','AHH'});
S.ed = uicontrol('style','edit',...
'units','pix',...
'position',[20 60 260 30],...
'fontsize',16);

set(S.ed,'keypressfcn',{@ed_kpfcn})
uicontrol(S.ed)

function [] = ed_kpfcn(varargin)
% Keypressfcn for the editbox.
E = varargin{2};

if strcmp(E.Key,'return')
return
end

if strcmp(E.Key,'backspace')
S.KEY = S.KEY(1:end-1);
if strcmp(S.KEY,'ACUF')
set(S.pp,'visible','off')
else
set(S.pp,'visible','on')
end
return
end

S.KEY = [S.KEY E.Character];

if strcmp(S.KEY,'ACUF')
set(S.pp,'visible','off')
else
set(S.pp,'visible','on')
end
end
end