How do I make a push button output a value of '1' to a text box, and then use that value and a double?
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Bryce Adamski
il 19 Ott 2017
Commentato: Bryce Adamski
il 26 Ott 2017
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.
0 Commenti
Risposta accettata
Geoff Hayes
il 20 Ott 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.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Environment and Settings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!