1

我正在尝试为我制作的井字游戏制作 GUI。到目前为止,这是我为 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”、“pause”和其他几个功能,但找不到我要找的东西。或者我不太明白如何使用这些功能。如何让我的功能等待这两个按钮之一被按下?如果按下另一个按钮,它应该没有效果。

4

1 回答 1

2

尝试使用预定义的问题对话框。有关更多详细信息,请参见此处

button = questdlg('How many players?', 'One', 'Two' );
于 2013-07-20T21:20:39.340 回答