Effacer les filtres
Effacer les filtres

How do I make a push button output a value of '1' to a text box, and then use that value and a double?

20 vues (au cours des 30 derniers jours)
I have a GUI that is supposed to act like a number pad, but I cannot get the buttons to actually output just a simple value. I am only attempting to get one button to work right now and will just mirror the results for the other buttons. I need help letting the button pass the value of '1' to display in a edit text box. This is for a touchscreen GUI so I need the number pad to be used to input values rather than a keyboard, please help.

Réponse acceptée

Geoff Hayes
Geoff Hayes le 20 Oct 2017
Bryce - how are you creating your GUI? With App Designer, GUIDE, or programmatically? In probably all three cases, your push button will have a callback and it is within that function that you will update the text box with the appropriate value.
If using GUIDE, you could do something like
% pushbutton1 is for the 1 key
function pushbutton1_Callback(hObject, eventdata, handles)
% get the current number from the text field
currentNumber = get(handles.text1, 'String');
% create the new number
newNumber = [currentNumber '1'];
% update the text
set(handles.text1, 'String', newNumber);
The callback uses the handle of the text field (from the handles structure as handles.text1) and gets the current string value. A '1' is then appended to this string and we then save it to the text field.
Your going to have a lot of duplicated code since there will be ten keys, so you may want to create a helper function that does much of the above.

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by