首页 > 解决方案 > 为什么即使条件为真,我的 If 语句也不起作用,但如果条件为真,则 else 仍在工作

问题描述

我有一个简单的 if else 语句,但我有一个问题,为什么即使 if 条件为真但 if 条件不起作用,但当 else 为真时它工作正常。

有人可以告诉我为什么我的 if 条件即使是真的也不起作用?

self.comboBoxCourse.currentIndexChanged.connect(self.courseChoosed)

这是 if else 语句:

def courseChoosed(self):
    if self.comboBoxCourse.currentIndex() == 0:
        self.pushButton_2.clicked.connect(self.courseSTEM)
        print("Your Current course is STEM")
    elif self.comboBoxCourse.currentIndex() == 1:
        self.pushButton_2.clicked.connect(self.courseICT)
        print('Your current course is ICT')
        print(self.comboBoxCourse.currentIndex())

如果我选择 STEM 这是 Index == 0: 这是真的,它正在显示打印消息,我不知道为什么但按钮不起作用。

在此处输入图像描述

如果组合框为 ==1: 并且按钮工作得很好,则 else 语句的结果。

else 语句的结果

有人可以告诉我为什么 if 语句中的按钮功能即使是真的也不起作用?

标签: pythonif-statementbutton

解决方案


推荐阅读