Python QT 无法从按钮运行 def



我正在尝试为Python制作的蛮力算法制作GUI。我目前正在使用Python 3.6和PyQt5。我目前遇到的问题是我无法让它运行定义。抱歉,如果这是一个简单的修复程序。错误是说在蛮力菜单对象中没有属性调用蛮力

这就是我目前收到的错误。 代码为:

    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_())

试试看:

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_())

相关内容

  • 没有找到相关文章

最新更新