How can I display results of my function onto a toggle button?
Show older comments
Im trying to create a tic tac toe game and I cant seem to figure out a way to display the result of my toggle button funtion to display on the button itself?
state1=get(hObject,'Value') if state1==get(hObject,'max') display('x'); elseif state1==get(hObject,'min') display('o'); set(handles.edit4,'String',X) end
thats the code for my first toggle button and one button press results in an x in the command window but I dont know how to display onto the "game board"
1 Comment
Sara
on 11 Jun 2014
how did you create a game board? is it inside the gui or do you want to print it into the command windows?
Answers (1)
Geoff Hayes
on 11 Jun 2014
I think that you almost have the code to do that, it is just that you are updating the edit4 text widget rather than the button itself. (Since you mention you want a way to display the result of my toggle button to display on the button itself.)
I did the following in a toggle button callback
% --- Executes on button press in togglebutton1.
function togglebutton1_Callback(hObject, eventdata, handles)
state1 = get(hObject,'Value'); % get the state like you
if state1==get(hObject,'max') % if depressed, set to X
set(hObject,'String','X');
else
set(hObject,'String','O'); % if not pressed, set to X
end
Almost identical to what you have, the only difference being that the code updates the toggle button string.
Categories
Find more on Strategy & Logic in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!