pyQt5_checkBox常用方法

# -*- coding:utf-8 -*-
"""
@Time:2022/3/23 22:24
@Author:小柠檬
@File:check_box.py
"""
from PyQt5 import uic, QtCore
from PyQt5.QtWidgets import QApplication


class CheckBox:

    def __init__(self):
        # 加载UI界面
        self.ui = uic.loadUi("check_box.ui")

        # 1.设置选中状态
        self.ui.checkBox.setChecked(True)

        # 2.设置未选中状态
        self.ui.checkBox.setChecked(False)

        # 3.判断是否选中
        check_box_status = self.ui.checkBox.isChecked()
        print(check_box_status)

        # 4.点击事件
        self.ui.checkBox.clicked.connect(self.slot_check_box)

    @staticmethod
    def slot_check_box():
        print('复选框被点击了')


def main():
    QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)  # 和designer设计的窗口比例一致
    app = QApplication([])
    check_box = CheckBox()
    check_box.ui.show()
    app.exec_()


if __name__ == '__main__':
    main()

你可能感兴趣的:(pyQt5,qt5,python)