How Can I Show a txt File in a GUI ?

14 次查看(过去 30 天)
I have a 5 txt file about informations of 5 different people . I designed a drop down menu about 5 people in the guı as you can see in the figure.For instance when I click to person 1 at the drop down it will show the first txt file. Should I put Edit field or text area into a guı to show the text files? How can I show these text files in the GUI ?

采纳的回答

Jorg Woehl
Jorg Woehl 2021-3-5
A text area would be the way to go, as it will show a scroll bar and wrap text if the content of the textfile is larger than the space available. Just make sure that you make it non-editable in App Designer (Inspector > Interactivity) if you only want to show the text but not allow the user to edit it.
I suppose you have one textfile per person. In this case, the callback for the dropdown menu could look similar to this:
value = app.DropDown.Value;
% choose the correct textfile depending on which person was selected
switch value
case 'Option 1'
myfile = 'person1.txt';
case 'Option 2'
...
end
% open the file and display its contents in the text area
fileID = fopen(myfile);
C = textscan(fileID, '%s', 'Delimiter', '\n');
app.TextArea.Value = C{1};
fclose(fileID);
To get to the callback, right-click on the dropdown menu and select Callbacks > DropDownValueChanged callback.
Note that you will have to adjust the callback code if you change the names of the options in the dropdown menu (Option 1, Option 2, etc.).

更多回答(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