How I make a pushbutton invisible in a GUI?
조회 수: 20 (최근 30일)
이전 댓글 표시
I has a picture of a drumset/percussion and wants to click a drum which then makes a sound. So I wants a button on my drum, but invisible. So I can still see the drum on my window figure without pushbutton.
My Script:
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[s,fs]=wavread('filename.wav');
sound(s,fs);
Thankyou..
댓글 수: 0
답변 (2개)
Stephen23
2016년 9월 23일
편집: Stephen23
2016년 9월 23일
Setting the Visible property to off will not work, because then the uicontrol does not respond to clicking.
Here are two alternatives that actually work, but are perhaps not as beautiful as an invisible, clickable button.
Button on top of an image
X = imread('drum.jpg');
fgh = figure('Color','white');
image(X)
axis off
axis image
uih = uicontrol(fgh,'Style','pushbutton', 'BackGroundColor','white',...
'Units','normalized','Position',[0.5,0.4,0.2,0.2], 'String','press',...
'Callback',@(h,e)disp('bang!'));
Button displaying an image
X = imread('drum.jpg');
fgh = figure('Color','white');
uih = uicontrol(fgh,'Style','pushbutton', 'BackGroundColor','white',...
'Units','pixels', 'Position',[20,20,200,200], 'String','press',...
'CData',X, 'Callback',@(h,e)disp('bang!'));
Both methods use this image:
댓글 수: 6
Stephen23
2016년 9월 23일
편집: Stephen23
2018년 3월 21일
I don't see any simple solution that makes the button invisible. So far I have shown you:
- making button invisible: does not work.
- button on top of image: works.
- button contains image: works.
One more option would be to write your own "button" by defining a callback that detects the mouse position and decides how to respond based on its position. For this you will have to start by reading these:
then you will have to use some kind of indexing to specify the required location, and define a callback function that uses this to trigger your code.
Amanda Irving
2019년 8월 8일
Starting in R2019a, there is a new component available called uiimage.
You can assign an image using the ImageSource property and assign a callback using the ImageClickedFcn:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!