带PYQT5按钮的OOP无法连接功能和一些错误

时间:2019-06-21 20:50:40

标签: python oop pyqt5

我的代码有很多错误,但是当我在youtube上查看一些类似的代码时,我从中学到了一些错误的代码,但是我的代码不起作用。

from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
import random
import sys

class Pencere(QWidget):
    def __init__(self):
        super().__init__()
        self.setUI()
    def setUI(self):
        self.setWindowTitle("Test Your Math...")
        self.r1 = QRadioButton("addition")
        self.r2 = QRadioButton("extraction")
        self.r3 = QRadioButton("multiplication")
        self.r4 = QRadioButton("division")

        h_box = QHBoxLayout()
        h_box.addWidget(self.r1)
        h_box.addWidget(self.r2)
        h_box.addWidget(self.r3)
        h_box.addWidget(self.r4)

        self.label_text = QLabel("Welcome To This Test.")
        self.label_text.setAlignment(Qt.AlignCenter)
        self.label_text.setStyleSheet("color: rgb(137,10,48);font-weight:bold; font-size: 16pt")
        v_box = QVBoxLayout()
        v_box.addWidget(self.label_text)
        v_box.addStretch()
        v_box.addLayout(h_box)


        self.a = QLineEdit("Write your answer here.")
        v_box.addWidget(self.a)
        self.startbutton = QPushButton()
        self.startbutton.setIcon(QIcon("startbutton.png"))
        self.startbutton.setIconSize(QSize(65,65))
        v_box.addWidget(self.startbutton)
        question_text =QLabel("Click start to see first question.")
        v_box.addWidget(question_text)
        self.setLayout(v_box)

        self.startbutton.clicked.connect(self.chg())

    def chg(self):
        if self.r1.isChecked():
            print("asdsada")


if __name__ == "__main__":
    app = QApplication([])
    pencere = Pencere()
    app.exec_()

chg函数不起作用,即使所有代码都不起作用,为什么我不知道

0 个答案:

没有答案