Python QT无法从按钮运行def

时间:2018-04-15 14:32:25

标签: python-3.x pyqt qt5

我正在尝试为Python制作的暴力算法制作GUI。我目前正在使用Python 3.6和PyQt5。我目前遇到的问题是我无法运行定义。对不起,如果这是一个简单的修复。错误是说在bruteforcemenu对象中没有属性callingBruteForce

这是我收到的当前错误。代码是:

    import sys
    from itertools import product
    from PyQt5.QtWidgets import (QWidget, QToolTip, 
    QPushButton, QApplication)
    from PyQt5.QtGui import QFont    


    def bruteForce():
        user_password = 'test'.upper()
        found = False
        BFcounter = 0
        BFclearCounter = 0
        passwordAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*"
     for length in range(1, 10): # it isn't reasonable to try a password more than this length
        password_to_attempt = product(passwordAlphabet, repeat=length)

        for attempt in password_to_attempt:
            attempt = ''.join(attempt) # <- Join letters together
            BFcounter += 1
            BFclearCounter += 1

            if BFcounter < 9999999:
                    if BFclearCounter > 21546:   # The higher the number, the faster the program runs.
                        print("Attempt Number:", BFcounter, "with attempt of", attempt)
                        BFclearCounter = 0

            elif BFcounter > 20000000 & BFcounter < 10000000:
                if BFclearCounter > 145665:   # The higher the number, the faster the program runs.
                    print("Attempt Number:", BFcounter, "with attempt of", attempt)
                    BFclearCounter = 0
            elif BFcounter > 20000001:
                if BFclearCounter > 29999956:   # The higher the number, the faster the program runs.
                        print("Attempt Number:", BFcounter, "with attempt of", attempt)
                        BFclearCounter = 0
            else:
                print("Attempt Number:", BFcounter, "with attempt of", attempt)                    


            if attempt == user_password:
                print("Attempt Number:", BFcounter, "with attempt of", attempt)
                print("Your password is: "+ attempt + " and was found in" , BFcounter, "attempts!")
                found = True
                break

        if found:
            break

class BruteForceMenu(QWidget):

    def __init__(self):
        super().__init__()

        self.initUI()


    def initUI(self):

        QToolTip.setFont(QFont('SansSerif', 10))

        self.setToolTip('This is a <b>QWidget</b> widget')

        bruteForce = QPushButton('Brute Force', self)
        bruteForce.setToolTip('This is a <b>QPushButton</b> widget')
        bruteForce.resize(bruteForce.sizeHint())
        bruteForce.move(50, 50)
        bruteForce.clicked.connect(self.callingbruteForce)

        self.setGeometry(300, 300, 300, 200)
        self.setWindowTitle('Main Menu!')
        self.show()

    def callingbruteforce(self):
        bruteForce()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = BruteForceMenu()
    sys.exit(app.exec_())

1 个答案:

答案 0 :(得分:0)

试一试:

var cash_advancetable = $('#cash_advancetable').DataTable({
            dom: 'Bfrtip',
            buttons: [
            ],
            processing: true,
            serverSide: true,
            ajax: "{{ route('refresh_cashadvance') }}",
            columns: [
                {render: function(data, type, full, meta){
                    return full.fname +" "+full.mname+" "+full.lname;
                }},
                {data: 'amount', name: 'amount'},
                {data: 'created_at', name: 'created_at'},
                {data: 'balance', name: 'balance'},
                {data: "action", orderable:false,searchable:false}
            ]
        });