How can I click a push button programmatically in App Designer?

92 vues (au cours des 30 derniers jours)
Anshuman Agrawal
Anshuman Agrawal le 31 Juil 2019
One of my pushbuttons when clicked does a bunch of calculations and I was wondering how to 'click' it in some other part of my code.
I know that I can create a helper function instead but I wanted to know if it was possible to just 'click' the button programmatically.

Réponse acceptée

Kojiro Saito
Kojiro Saito le 1 Août 2019
You can call the button pushed callback function programmatically, so if your callback looks like this,
% Button pushed function: Button
function ButtonPushed(app, event)
% Do something
end
you can call it by the following.
ButtonPushed(app, matlab.ui.eventdata.ButtonPushedData)
  1 commentaire
Eric Delgado
Eric Delgado le 22 Sep 2022
@Kojiro Saito, is it right? At least for me, this approach creates an empty event, so it's not possible to use its properties "Source" or "Value" and "PreviousValue" (in the case of a "state button"). How to create a real event programmatically?
% Event created for a real click in a button:
event =
ButtonPushedData with properties:
Source: [1×1 Button]
EventName: 'ButtonPushed'
% Event created programmatically (using your approach)
event =
ButtonPushedData with properties:
Source: [0×0 handle]
EventName: ''

Connectez-vous pour commenter.

Plus de réponses (1)

William
William le 26 Mai 2023
Hi. Very new to appdesigner and gui building, but ... I have been able to programmatically push a button in my startup function using
app.ButtonPushed
seems to work very well. I can even "pre-check" checkboxes using some like
app.checkbox.value=1
and then I can programmatically push the button that uses this data. Very slick

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by