How I make a pushbutton invisible in a GUI?

20 ビュー (過去 30 日間)
sibolis naburju.id
sibolis naburju.id 2016 年 9 月 23 日
回答済み: Amanda Irving 2019 年 8 月 8 日
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..

回答 (2 件)

Stephen23
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
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:
  1. making button invisible: does not work.
  2. button on top of image: works.
  3. 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.
Stephen23
Stephen23 2016 年 9 月 23 日
編集済み: Stephen23 2018 年 3 月 21 日
"How i do that?" I showed you already. This is the second method in my answer. I even tested it and showed you a screenshot.

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


Amanda Irving
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:

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by