首页 > 解决方案 > 当我点击 QPushButton 时,如何根据 QRadioButton 修改被调用的函数?

问题描述

我有三个 QRadioButtons。一次只能选择一个。我有一个 QPushButton,它必须根据所选的 QRadioButton 调用不同的函数。

示例:如果选择 QRadioButton #1,则该按钮在单击时执行功能 #1。如果选择 QRadioButton #2,则相同的按钮执行功能 #2,依此类推。

标签: pythonqtpyqt

解决方案


我不得不为我的代码稍微改变一下,它确实有效。谢谢!

...
class Window(QWidget):
    def __init__(self):
    ...
    def init_ui(self):
        ...    
        self.bnt.clicked.connect(lambda: self.decision_maker())
        ...

    def decision_maker(self):
        if self.radiobutton1.isChecked():
            do_something_1()
        elif self.radiobutton2.isChecked():
            do_something_2()
        ...

推荐阅读