How to set a value from code or callback to a edit text box

How to set a value from code or callback to a edit text box I have one text edit box "edit1" on gui.fig, and the code in gui.m with:
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @gui_OpeningFcn, ...
'gui_OutputFcn', @gui_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 gui_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = gui_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function varargout = gui(varargin)
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
}

 採用された回答

Gerd
Gerd 2011 年 7 月 4 日

1 投票

Hi danny,
in your function edit1_CreateFcn(hObject, eventdata, handles) you can set the "String" value by typing
set(hObject,'String','Hello World');
Gerd

4 件のコメント

danny krawz
danny krawz 2011 年 7 月 4 日
Yes Thank's realy work, but to insert a single value from a single text file from my computer it's possible?
danny krawz
danny krawz 2011 年 7 月 4 日
or to save "Hello World" to text file and open then to insert in edit text it's possible? If i do this my project is done thank's
Gerd
Gerd 2011 年 7 月 5 日
Hi danny,
sure it is possible. Lets say you have a test.txt file where you only have one line included "Hello World".
Again in the edit1_CreateFcn you can write
fid = fopen('test.txt');
line = fgetl(fid);
fclose(fid);
set(hObject,'String',line);
Daniel Liberman
Daniel Liberman 2020 年 3 月 22 日
Hi Gred,
What if I have an edit text and several popup menus, and I want to insert a different text from text files on my computer to the edit text box for each popupmenu?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

2011 年 7 月 4 日

コメント済み:

2020 年 3 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by