QRadioButton是一个单选按钮,可以打开(选中)或关闭(取消选中)。在一组单选按钮中,一次只能选中其中一个按钮。

打开或关闭按钮,都会发出toggled()信号。使用isChecked()可以查看是否选择了一个特定的按钮。

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QRadioButton, QLabel
from PyQt5.QtGui import QPixmap

class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.resize(250, 155)
        self.setWindowTitle('title')

        self.on_button = QRadioButton('ON', self)
        self.on_button.toggled.connect(self.choose)

        self.off_button = QRadioButton('OFF', self)
        self.off_button.move(0, 30)
        self.off_button.toggled.connect(self.choose)

        self.label = QLabel(self)
        self.label.setGeometry(60, 30, 100, 100)

        self.show()
    
    def choose(self):
        if self.on_button.isChecked():
            self.label.setPixmap(QPixmap('D:\png\on.png'))
        else:
            self.label.setPixmap(QPixmap('D:\png\off.png'))

if __name__ == "__main__":
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

PyQt5 QRadioButton按钮 PyQt5 QRadioButton按钮

相关文章:

  • 2021-05-22
  • 2021-10-29
  • 2022-12-23
  • 2021-04-04
  • 2021-11-05
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-23
  • 2021-09-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-07
  • 2021-11-26
相关资源
相似解决方案