Reputation: 11
"""I have defined certain functions to carry out password encryption. Though the encryptions are functioning properly, I'm unable to use the GUI, written using PyQt5. To be more specific, I'm unable to execute my functions based on the type of encryption selected by the user in the drop-down box/QCombobox. """
class App(QMainWindow):
def __init__(self):
super().__init__()
self.title = 'Password encryption'
self.left = 10
self.top = 10
self.width = 400
self.height = 200
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
# Create textbox
self.textbox = QLineEdit(self)
self.textbox.move(30, 35)
self.textbox.resize(350, 30)
# Create a button in the window
drop = QComboBox(self)
drop.addItem("None")
drop.addItem("modlensq")
drop.addItem("fishcrypt")
drop.addItem("bitman")
drop.addItem("caesarcipher")
drop.addItem("encryptcipher2")
drop.addItem("blowfishencryption")
drop.addItem("AES")
drop.move(45, 90)
inp = QLabel(self)
inp.setText("Enter the password:")
inp.move(5, 5)
# Create a drop down list to select in the window
self.button = QPushButton('Encrypt', self)
self.button.move(135, 150)
# connect button to function on_click
self.button.clicked.connect(self.on_click)
self.show()
@pyqtSlot()
def on_click(self):
textboxValue = self.textbox.text()
QMessageBox.question(self, 'password after encryption', "encrypted form: " + textboxValue , QMessageBox.Ok,
QMessageBox.Ok)
self.textbox.setText("")
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())
Upvotes: 1
Views: 2288
Reputation: 13641
Add a Signal:
drop.activated[str].connect(self.onActivated)
http://doc.qt.io/qt-5/qcombobox.html#activated-1 This signal is sent when the user chooses an item in the combobox.
Try it:
from PyQt5 import Qt
class App(Qt.QMainWindow):
def __init__(self):
super().__init__()
self.title = 'Password encryption'
self.left = 500
self.top = 100
self.width = 400
self.height = 200
self.comboText = None # +++
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
# Create textbox
self.textbox = Qt.QLineEdit(self)
self.textbox.move(30, 35)
self.textbox.resize(350, 30)
# Create a button in the window
drop = Qt.QComboBox(self)
drop.addItem("None")
drop.addItem("modlensq")
drop.addItem("fishcrypt")
drop.addItem("bitman")
drop.addItem("caesarcipher")
drop.addItem("encryptcipher2")
drop.addItem("blowfishencryption")
drop.addItem("AES")
drop.move(45, 90)
drop.activated[str].connect(self.onActivated) # +++
inp = Qt.QLabel(self)
inp.setText("Enter the password:")
inp.move(5, 5)
# Create a drop down list to select in the window
self.button = Qt.QPushButton('Encrypt', self)
self.button.move(135, 150)
# connect button to function on_click
self.button.clicked.connect(self.on_click)
self.show()
@Qt.pyqtSlot()
def on_click(self):
textboxValue = self.textbox.text()
Qt.QMessageBox.question(self, 'password after encryption',
"encrypted form: {}, <br>ComboBoxItem: {} "\
.format(textboxValue, self.comboText) , # +++
Qt.QMessageBox.Ok, Qt.QMessageBox.Ok)
self.textbox.setText("")
# +++
def onActivated(self, text):
self.comboText = text
if __name__ == '__main__':
import sys
app = Qt.QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())
Upvotes: 1