Thread Subject: Gui Pushbutton default= off

Subject: Gui Pushbutton default= off

From: ching l

Date: 20 Jul, 2009 21:34:01

Message: 1 of 7

Hello there,

How do I set the pushbutton off by default?
This is what I've tried but apparently that isn't right.

-----------------------------------------------------------
function next_Callback(hObject, eventdata, handles)

handles = guidata(gcbo);

set(hObject, 'enable', 'off')

guidata(gcbo, handles);

------------------------------------------------------------

Please advise.

Thanks.

Subject: Gui Pushbutton default

From: Nathan

Date: 20 Jul, 2009 21:46:55

Message: 2 of 7

On Jul 20, 2:34 pm, "ching l" <ching...@hotmail.com> wrote:
> Hello there,
>
> How do I set the pushbutton off by default?
> This is what I've tried but apparently that isn't right.
>
> -----------------------------------------------------------
> function next_Callback(hObject, eventdata, handles)
>
> handles = guidata(gcbo);
>
> set(hObject, 'enable', 'off')
>
> guidata(gcbo, handles);
>
> ------------------------------------------------------------
>
> Please advise.
>
> Thanks.

What do you mean by "off"? Do you mean disabled, or do you mean
invisible?
In either case...
Let's say your push button tag is pushbutton1

To disable it:
set(handles.pushbutton1,'Enable','off')

To make it invisible:
set(handles.pushbutton1,'Visible','off')

Either of those should work.
-Nathan

Subject: Gui Pushbutton default

From: ching l

Date: 21 Jul, 2009 08:37:01

Message: 3 of 7

Nathan <ngreco32@gmail.com> wrote in message <14ea2dbd-e56d-4b48-8fdc-39b0060a5ee4@p36g2000prn.googlegroups.com>...
> On Jul 20, 2:34?pm, "ching l" <ching...@hotmail.com> wrote:
> > Hello there,
> >
> > How do I set the pushbutton off by default?
> > This is what I've tried but apparently that isn't right.
> >
> > -----------------------------------------------------------
> > function next_Callback(hObject, eventdata, handles)
> >
> > handles = guidata(gcbo);
> >
> > set(hObject, 'enable', 'off')
> >
> > guidata(gcbo, handles);
> >
> > ------------------------------------------------------------
> >
> > Please advise.
> >
> > Thanks.
>
> What do you mean by "off"? Do you mean disabled, or do you mean
> invisible?
> In either case...
> Let's say your push button tag is pushbutton1
>
> To disable it:
> set(handles.pushbutton1,'Enable','off')
>
> To make it invisible:
> set(handles.pushbutton1,'Visible','off')
>
> Either of those should work.
> -Nathan

Hello, my push button tag is set to next.

my codes are,

function next_Callback(hObject, eventdata, handles)

set(handles.next,'Enable','off')

but it doesn't seem to work.

Did i miss out anything?

Subject: Gui Pushbutton default

From: Andy Eisenberg

Date: 21 Jul, 2009 13:09:02

Message: 4 of 7

"ching l" <chinglnc@hotmail.com> wrote in message <h43und$mqu$1@fred.mathworks.com>...
> Nathan <ngreco32@gmail.com> wrote in message <14ea2dbd-e56d-4b48-8fdc-39b0060a5ee4@p36g2000prn.googlegroups.com>...
> > On Jul 20, 2:34?pm, "ching l" <ching...@hotmail.com> wrote:
> > > Hello there,
> > >
> > > How do I set the pushbutton off by default?
> > > This is what I've tried but apparently that isn't right.
> > >
> > > -----------------------------------------------------------
> > > function next_Callback(hObject, eventdata, handles)
> > >
> > > handles = guidata(gcbo);
> > >
> > > set(hObject, 'enable', 'off')
> > >
> > > guidata(gcbo, handles);
> > >
> > > ------------------------------------------------------------
> > >
> > > Please advise.
> > >
> > > Thanks.
> >
> > What do you mean by "off"? Do you mean disabled, or do you mean
> > invisible?
> > In either case...
> > Let's say your push button tag is pushbutton1
> >
> > To disable it:
> > set(handles.pushbutton1,'Enable','off')
> >
> > To make it invisible:
> > set(handles.pushbutton1,'Visible','off')
> >
> > Either of those should work.
> > -Nathan
>
> Hello, my push button tag is set to next.
>
> my codes are,
>
> function next_Callback(hObject, eventdata, handles)
>
> set(handles.next,'Enable','off')
>
> but it doesn't seem to work.
>
> Did i miss out anything?

The following works for me (saved as test.m):

function test
    f=figure('Units','normalized',...
        'Position',[.4 .4 .2 .2],...
        'Visible','on');

    push1=uicontrol('Style','pushbutton',...
        'Parent',f,...
        'Units','characters',...
        'Position',[5 2 20 2],...
        'Callback',{@push1_Callback},...
        'String','Disable');

    function push1_Callback(src,eventdata)
        set(push1,'Enable','off');
    end
end

Can you say a little bit more about what exactly went wrong?

Subject: Gui Pushbutton default

From: ching l

Date: 21 Jul, 2009 15:09:01

Message: 5 of 7

"Andy Eisenberg" <theorigamist@gmail.com> wrote in message <h44ele$30a$1@fred.mathworks.com>...
> "ching l" <chinglnc@hotmail.com> wrote in message <h43und$mqu$1@fred.mathworks.com>...
> > Nathan <ngreco32@gmail.com> wrote in message <14ea2dbd-e56d-4b48-8fdc-39b0060a5ee4@p36g2000prn.googlegroups.com>...
> > > On Jul 20, 2:34?pm, "ching l" <ching...@hotmail.com> wrote:
> > > > Hello there,
> > > >
> > > > How do I set the pushbutton off by default?
> > > > This is what I've tried but apparently that isn't right.
> > > >
> > > > -----------------------------------------------------------
> > > > function next_Callback(hObject, eventdata, handles)
> > > >
> > > > handles = guidata(gcbo);
> > > >
> > > > set(hObject, 'enable', 'off')
> > > >
> > > > guidata(gcbo, handles);
> > > >
> > > > ------------------------------------------------------------
> > > >
> > > > Please advise.
> > > >
> > > > Thanks.
> > >
> > > What do you mean by "off"? Do you mean disabled, or do you mean
> > > invisible?
> > > In either case...
> > > Let's say your push button tag is pushbutton1
> > >
> > > To disable it:
> > > set(handles.pushbutton1,'Enable','off')
> > >
> > > To make it invisible:
> > > set(handles.pushbutton1,'Visible','off')
> > >
> > > Either of those should work.
> > > -Nathan
> >
> > Hello, my push button tag is set to next.
> >
> > my codes are,
> >
> > function next_Callback(hObject, eventdata, handles)
> >
> > set(handles.next,'Enable','off')
> >
> > but it doesn't seem to work.
> >
> > Did i miss out anything?
>
> The following works for me (saved as test.m):
>
> function test
> f=figure('Units','normalized',...
> 'Position',[.4 .4 .2 .2],...
> 'Visible','on');
>
> push1=uicontrol('Style','pushbutton',...
> 'Parent',f,...
> 'Units','characters',...
> 'Position',[5 2 20 2],...
> 'Callback',{@push1_Callback},...
> 'String','Disable');
>
> function push1_Callback(src,eventdata)
> set(push1,'Enable','off');
> end
> end
>
> Can you say a little bit more about what exactly went wrong?

THANKS A LOT FOR THAT!! your codes worked!

I didn't really create the gui by "codes", instead i created the Gui by Guide Quickstart, then drag the pushbutton from the menu to the build window etc, it will then save in m-file and fig. But theoretically it should be the same?

so inside the m-file, in the next_Callback function, I inserted the codes as above.
However,when I saved it and opened the fig file, it still remains enable. Anyway, I managed to set it as "default disable" by double click on the pushbutton and disable it on the ENABLE menu (setting as "off").

I still don't understand why your codes don't work in this way, isn't it should be the same?

 
 

Subject: Gui Pushbutton default

From: Andy Eisenberg

Date: 21 Jul, 2009 16:13:01

Message: 6 of 7

"ching l" <chinglnc@hotmail.com> wrote in message <h44lmd$qii$1@fred.mathworks.com>...
> "Andy Eisenberg" <theorigamist@gmail.com> wrote in message <h44ele$30a$1@fred.mathworks.com>...
> > "ching l" <chinglnc@hotmail.com> wrote in message <h43und$mqu$1@fred.mathworks.com>...
> > > Nathan <ngreco32@gmail.com> wrote in message <14ea2dbd-e56d-4b48-8fdc-39b0060a5ee4@p36g2000prn.googlegroups.com>...
> > > > On Jul 20, 2:34?pm, "ching l" <ching...@hotmail.com> wrote:
> > > > > Hello there,
> > > > >
> > > > > How do I set the pushbutton off by default?
> > > > > This is what I've tried but apparently that isn't right.
> > > > >
> > > > > -----------------------------------------------------------
> > > > > function next_Callback(hObject, eventdata, handles)
> > > > >
> > > > > handles = guidata(gcbo);
> > > > >
> > > > > set(hObject, 'enable', 'off')
> > > > >
> > > > > guidata(gcbo, handles);
> > > > >
> > > > > ------------------------------------------------------------
> > > > >
> > > > > Please advise.
> > > > >
> > > > > Thanks.
> > > >
> > > > What do you mean by "off"? Do you mean disabled, or do you mean
> > > > invisible?
> > > > In either case...
> > > > Let's say your push button tag is pushbutton1
> > > >
> > > > To disable it:
> > > > set(handles.pushbutton1,'Enable','off')
> > > >
> > > > To make it invisible:
> > > > set(handles.pushbutton1,'Visible','off')
> > > >
> > > > Either of those should work.
> > > > -Nathan
> > >
> > > Hello, my push button tag is set to next.
> > >
> > > my codes are,
> > >
> > > function next_Callback(hObject, eventdata, handles)
> > >
> > > set(handles.next,'Enable','off')
> > >
> > > but it doesn't seem to work.
> > >
> > > Did i miss out anything?
> >
> > The following works for me (saved as test.m):
> >
> > function test
> > f=figure('Units','normalized',...
> > 'Position',[.4 .4 .2 .2],...
> > 'Visible','on');
> >
> > push1=uicontrol('Style','pushbutton',...
> > 'Parent',f,...
> > 'Units','characters',...
> > 'Position',[5 2 20 2],...
> > 'Callback',{@push1_Callback},...
> > 'String','Disable');
> >
> > function push1_Callback(src,eventdata)
> > set(push1,'Enable','off');
> > end
> > end
> >
> > Can you say a little bit more about what exactly went wrong?
>
> THANKS A LOT FOR THAT!! your codes worked!
>
> I didn't really create the gui by "codes", instead i created the Gui by Guide Quickstart, then drag the pushbutton from the menu to the build window etc, it will then save in m-file and fig. But theoretically it should be the same?
>
> so inside the m-file, in the next_Callback function, I inserted the codes as above.
> However,when I saved it and opened the fig file, it still remains enable. Anyway, I managed to set it as "default disable" by double click on the pushbutton and disable it on the ENABLE menu (setting as "off").
>
> I still don't understand why your codes don't work in this way, isn't it should be the same?
>
>
>

---------------------------------------------------------------------------------------------------------------------

Okay, I think I see the issue here. To explain (and sum up):

It is not the same to create a GUI in GUIDE or to create a GUI programmatically (by typing the commands directly into an m-file). When you create a GUI programmatically, you need to explicitly set the properties you want when you create an object (or beforehand by defining default properties for all objects of a certain type). So in my code, the command

uicontrol('Style','pushbutton','Enable','off');

would create a pushbutton that is disabled by default (i.e. when it is created), which sounds like what you're looking for.

I mistakenly thought you were trying to use a pushbutton to disable itself (which is what the code I posted before did). The Callback function for a pushbutton is called when the button is pushed, not when it is created. That's why your code didn't disable the push button by default.

If you create a GUI using GUIDE, the properties that you set in the Property Inspector are saved to the .fig file and are used to create the objects. That's why you have to set the 'Enable' property to 'off' in the property inspector in order to get the push button to be disabled by default when your GUI is run. Alternatively, you can use a CreateFcn, which is called when the object is created. This would look something like:

function push1_CreateFcn(hObject,eventdata,handles)
    set(push1,'Enable','off');
end

(If you set 'Enable' to 'off' using the property inspector, you don't need to include this in your m-file as it will be in your .fig file. Either way, you should not put this set command in the Callback function, as that won't happen until the button is pressed.)

Does that answer your question?

Subject: Gui Pushbutton default

From: ching l

Date: 21 Jul, 2009 17:40:18

Message: 7 of 7

"Andy Eisenberg" <theorigamist@gmail.com> wrote in message <h44ped$2c8$1@fred.mathworks.com>...
> "ching l" <chinglnc@hotmail.com> wrote in message <h44lmd$qii$1@fred.mathworks.com>...
> > "Andy Eisenberg" <theorigamist@gmail.com> wrote in message <h44ele$30a$1@fred.mathworks.com>...
> > > "ching l" <chinglnc@hotmail.com> wrote in message <h43und$mqu$1@fred.mathworks.com>...
> > > > Nathan <ngreco32@gmail.com> wrote in message <14ea2dbd-e56d-4b48-8fdc-39b0060a5ee4@p36g2000prn.googlegroups.com>...
> > > > > On Jul 20, 2:34?pm, "ching l" <ching...@hotmail.com> wrote:
> > > > > > Hello there,
> > > > > >
> > > > > > How do I set the pushbutton off by default?
> > > > > > This is what I've tried but apparently that isn't right.
> > > > > >
> > > > > > -----------------------------------------------------------
> > > > > > function next_Callback(hObject, eventdata, handles)
> > > > > >
> > > > > > handles = guidata(gcbo);
> > > > > >
> > > > > > set(hObject, 'enable', 'off')
> > > > > >
> > > > > > guidata(gcbo, handles);
> > > > > >
> > > > > > ------------------------------------------------------------
> > > > > >
> > > > > > Please advise.
> > > > > >
> > > > > > Thanks.
> > > > >
> > > > > What do you mean by "off"? Do you mean disabled, or do you mean
> > > > > invisible?
> > > > > In either case...
> > > > > Let's say your push button tag is pushbutton1
> > > > >
> > > > > To disable it:
> > > > > set(handles.pushbutton1,'Enable','off')
> > > > >
> > > > > To make it invisible:
> > > > > set(handles.pushbutton1,'Visible','off')
> > > > >
> > > > > Either of those should work.
> > > > > -Nathan
> > > >
> > > > Hello, my push button tag is set to next.
> > > >
> > > > my codes are,
> > > >
> > > > function next_Callback(hObject, eventdata, handles)
> > > >
> > > > set(handles.next,'Enable','off')
> > > >
> > > > but it doesn't seem to work.
> > > >
> > > > Did i miss out anything?
> > >
> > > The following works for me (saved as test.m):
> > >
> > > function test
> > > f=figure('Units','normalized',...
> > > 'Position',[.4 .4 .2 .2],...
> > > 'Visible','on');
> > >
> > > push1=uicontrol('Style','pushbutton',...
> > > 'Parent',f,...
> > > 'Units','characters',...
> > > 'Position',[5 2 20 2],...
> > > 'Callback',{@push1_Callback},...
> > > 'String','Disable');
> > >
> > > function push1_Callback(src,eventdata)
> > > set(push1,'Enable','off');
> > > end
> > > end
> > >
> > > Can you say a little bit more about what exactly went wrong?
> >
> > THANKS A LOT FOR THAT!! your codes worked!
> >
> > I didn't really create the gui by "codes", instead i created the Gui by Guide Quickstart, then drag the pushbutton from the menu to the build window etc, it will then save in m-file and fig. But theoretically it should be the same?
> >
> > so inside the m-file, in the next_Callback function, I inserted the codes as above.
> > However,when I saved it and opened the fig file, it still remains enable. Anyway, I managed to set it as "default disable" by double click on the pushbutton and disable it on the ENABLE menu (setting as "off").
> >
> > I still don't understand why your codes don't work in this way, isn't it should be the same?
> >
> >
> >
>
> ---------------------------------------------------------------------------------------------------------------------
>
> Okay, I think I see the issue here. To explain (and sum up):
>
> It is not the same to create a GUI in GUIDE or to create a GUI programmatically (by typing the commands directly into an m-file). When you create a GUI programmatically, you need to explicitly set the properties you want when you create an object (or beforehand by defining default properties for all objects of a certain type). So in my code, the command
>
> uicontrol('Style','pushbutton','Enable','off');
>
> would create a pushbutton that is disabled by default (i.e. when it is created), which sounds like what you're looking for.
>
> I mistakenly thought you were trying to use a pushbutton to disable itself (which is what the code I posted before did). The Callback function for a pushbutton is called when the button is pushed, not when it is created. That's why your code didn't disable the push button by default.
>
> If you create a GUI using GUIDE, the properties that you set in the Property Inspector are saved to the .fig file and are used to create the objects. That's why you have to set the 'Enable' property to 'off' in the property inspector in order to get the push button to be disabled by default when your GUI is run. Alternatively, you can use a CreateFcn, which is called when the object is created. This would look something like:
>
> function push1_CreateFcn(hObject,eventdata,handles)
> set(push1,'Enable','off');
> end
>
> (If you set 'Enable' to 'off' using the property inspector, you don't need to include this in your m-file as it will be in your .fig file. Either way, you should not put this set command in the Callback function, as that won't happen until the button is pressed.)
>
> Does that answer your question?

Thanks andy!! that's VERY HELPFUL!!! CHeers!

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
adding a timerc... Y1lmaz 13 Aug, 2009 06:34:06
pushbutton ching l 20 Jul, 2009 17:39:02
gui ching l 20 Jul, 2009 17:39:02
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com