我希望在根据结果进行一些处理后创建按钮,我希望它们可以点击。
这是我尝试的内容:
rename_attribute(self, "button", "button_{}".format(name))
self.OpenVid函数用VLC打开视频。
问题是每个按钮都会打开相同的视频,即操作列表中的最后一个视频。 好像 button.clicked.connect 覆盖了之前循环中的每个按钮。
我尝试过使用 self.button ,并在每个循环结束时将其重命名为:
def rename_attribute(object_, old_attribute_name, new_attribute_name):
setattr(object_, new_attribute_name, getattr(object_, old_attribute_name))
delattr(object_, old_attribute_name)
具有以下功能:
int play(Player &Player1, Player &Player2)
{
int answer = 0, guess = 0;
srand(22);
answer = rand() %100;
bool win = false;
while (!win)
{
cout<< "Player1s' turn to guess " <<end1;
guess = Player1.getGuess();
win = checkForWin(guess, answer);
if (win) return 0;
cout<< "Player2's turn to guess " <<end1;
guess = Player2.getGuess();
win = checkForWin(guess, answer);
}
}
int main()
{
system("COLOR 1E");
Humanplayer Player1,Player2;
play( Player1, Player2);
system("pause");
getch();
}
但是我得到了相同的结果: self.button.clicked.connect 似乎仍然会重写其他按钮,即使它们有不同的名称。