How can I use uigetfile when I click on an edit text in a GUI?

7 views (last 30 days)
I have an edit text box that says "Choose the file you would like to import". I would like to be able to click on it and have a file selector open up. I have tried using this:
if handles.edit7.Value==1 %%If i click on it
file=uigetfile('*.txt')
end
as if it was a pushbutton, but it doesn't work.

Answers (1)

Thiago Henrique Gomes Lobato
Edited: Thiago Henrique Gomes Lobato on 5 Apr 2020
You can't. Every GUI component has it's own callbacks, for the edit text element you have callbacks such as key press/release and callback after write something but nothing that it is called as soon as you click on it. It you think about it, it makes really no sense to have an edit text that calls a function, otherwise it would be a pushbutton. I really don't see any reason why this could be preffered from a simple pushbutton, specially in respect to the GUI user iteration, it would be just too confusing. If the idea is that the user would be able to edit the path after loading it, it would be way cleaner to have an edit text and a pushbutton at the side of it, then the pushbutton would call the uigetfile function and you could show the path at the edit box and let the user change it.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!