为什么即使条件为真,If语句也不起作用,而如果条件为真,else语句却起作用

2024-09-30 00:34:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个简单的if-else语句,但是我有一个问题,为什么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:这是真的,它显示的是打印消息,我不知道为什么,但按钮不起作用。你知道吗

enter image description here

如果组合框==1:并且按钮工作正常,则返回else语句的结果。你知道吗

result of else statement

有人能告诉我为什么if语句中的button函数即使是true也不起作用吗?你知道吗


Tags: selfyourifisconnect语句条件else

热门问题