1
我想爲我做的一個tic tac腳趾遊戲做一個GUI。下面是我對GUI至今代碼:MATLAB:如何讓我的功能等待GUI輸入
function fig=TTTGUI()for
close all
%initial creation
fig=figure('pos',[100 50 820 640]);
txtbx=uicontrol('style','text','parent',fig,'pos',[640 320 160 300]);
B0=uicontrol('style','pushbutton','parent',fig,'pos',[640 200 40 40],'string',0);
B1=uicontrol('style','pushbutton','parent',fig,'pos',[680 200 40 40],'string',1);
B2=uicontrol('style','pushbutton','parent',fig,'pos',[720 200 40 40],'string',2);
B3=uicontrol('style','pushbutton','parent',fig,'pos',[760 200 40 40],'string',3);
%set number of players
players=[];
set(txtbx,'string','how many players? (1 or 2)');
set(B1,'callback','players=1;');
set(B2,'callback','players=2;');
%stop and wait here
end
我想我所有的功能在此時停止,等待變量players
變化,這隻能從按鈕1或2分被壓發生。
我看過'waitfor','uiwait','暫停'和一些其他功能,但是我找不到我在找什麼。或者,我可能不太瞭解如何使用這些功能。 如何讓我的功能等待這兩個按鈕之一被按下?如果另一個按鈕被按下,它應該沒有效果。