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

조회 수: 3 (최근 30일)
Anthony Gaetani
Anthony Gaetani 2020년 4월 5일
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.

답변 (1개)

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2020년 4월 5일
편집: Thiago Henrique Gomes Lobato 2020년 4월 5일
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.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by